[mod_python] forks, daemons and other beasts

Scott Chapman scott_list at mischko.com
Tue Feb 14 12:12:08 EST 2006


Daniel Nogradi wrote:
> Sorry everyone, a long post follows :)
> 
> 
> Many times there is need for a mod_python program to respond (send a
> page) to the client after receiving a request and at the same time
> start a subprocess which typically takes quite long and waiting for it
> to finish is not necessary. So the situation is this: (1) request
> comes from client (2) server processes the request (3) server starts a
> subprocess and don't wait for it to finish (4) send a response to the
> client. Actually, (3) and (4) could be interchanged.
> 
> What is the best way to do this?

In cases like this, I've used a python cron script that checks for new files in 
a directory and deals with them when it finds them.

One script, no threads so no race conditions, etc.  Make it check the upload 
directory for files that are not being written to and deal with them one at a 
time.  That way the post-processing does not take up an inordinate amount of 
resources as well.  Anything that Apache spawns could get into scalability issues.

All this talk of threads and spawning things and handling sigterms, sigkills, 
etc. is probably too big of a hammer.

Happy post-processing,
Scott


More information about the Mod_python mailing list