[mod_python] execution time limit

Graham Dumpleton grahamd at dscpl.com.au
Tue Jan 9 18:10:09 EST 2007


Michael Rasmussen wrote ..
> > You've lost me. What cookbook are you talking about?
> > 
> Python cookbook: ISBN: 0-596-00167-3
> 
> > 
> > Can you provide a better description?
> > 
> 
> Assuming we are called with this URL: http://www.some.domain/my/script
> Assuming myscript.py is designated to handle requests for /my/script
> Assuming myscript.py has implemented the function run
> Assuming timeout is 30 sec.
> 
> But what really goes on is that this call are delegated to a controller
> script which directs the call to a script on the server. E.g the server
> has a controller which is delegated any request despite of the URL. It
> splits the request up in main parts an then calls myscript.py. This call
> is carrying out by starting myscript.py in a new thread in either of
> two ways:
> 
> 1:
>     t1 = myscript.MyScript()
>     t1.start()
>     t1.join(30.0)
>     return http code 500 to caller
> 
> 2:
>   (Assumption myscript.MyScript has implemented self destruction as the
> example from the python cookbook)
>     t1 = myscript.MyScript()
>     t1.start()
>     t1.join()
>     return http code 500 to caller
> 
> The must elegant solution would be 2. IMHO.
> 
> So you see, it is not the apache child process I am killing but a
> thread running inside that apache process. The apache process stays
> alive and is unknowing of what actually goes on. I think this is
> thread safe, at least when discussing the actual apache child
> processes.

Which when you take out killing of process it is exactly what I was talking about
in my initial post. Posting again what I said:

   Either way you would have to program such ability within the script. Ie., if
   the script is performing some sort of calculation, it would need to
   occasionally check itself how long it has been going and abort if need be.
   If you are communicating with other processes, rather than block you are
   going to have to use some sort of mechanism which will allow you to timeout
   an operation. Database systems don't usually allow this though. Depending on
   the circumstances, you may be able to farm the operation off to a distinct
   thread with the parent waiting for the thread to complete, but if it doesn't
   complete in time for it to send back failure. The separate thread will still
   continue until it completes though as not easy to kill threads.

This sort of stuff very much has to be done by a user in their handlers, it can't
be done as a standard feature of mod_python as it would be impossible to
come up with something that would work for all users code.

Graham


More information about the Mod_python mailing list