[mod_python] Starting a background process with mod_python?

Graham Dumpleton grahamd at dscpl.com.au
Sun Jan 14 17:15:24 EST 2007


keith at uglyslug.com wrote ..
> 
> I want to have a user click a 'submit' button on an HTML form, submit to
> a
> mod_python page, and have that mod_python page start 3 or 4 processes in
> the background which then run for hours and hours and hours. Obviously
> a
> result should be returned to the user before the hours and hours and hours
> are up.
> 
> I'm a bit of a python and mod_python newbie, and I tried some stuff with
> the 'threading' library, but no luck so far. Can anyone give me a working
> example?

Create a long running daemon process which runs separately to Apache
and which embeds an XML-RPC server in. Have the Apache request handler
use an XML-RPC client to make calls against the backend process to
request it do what needs to be done. The backend process can fire off
what is needed, including possibly fork/execing to run stuff as a separate
process. The XML-RPC request can return as soon as the separate process
is started.

Separating things like this so that it is a backend process which is doing
any fork/execing is much more preferable than having Apache child
processes do it.

Graham


More information about the Mod_python mailing list