[mod_python] Re: forks, daemons and other beasts

Robert Brewer fumanchu at amor.org
Sat Feb 11 19:48:25 EST 2006

Daniel Nogradi wrote:
> users upload a zip file and should get an acknowledgement
> that the upload was successful. The server should start
> unpacking the archive, check if the files are okay and
> move them to a directory. All of this can take quite long,
> so the acknowledgement should be sent before this
> unpacking/checking/moving finishes.

and Graham Dumpleton replied:
> The suggestion I gave wouldn't preclude an acknowledgement
> being sent before the unpacking begins.
> Have you simply considered using a separate thread to do the
> unpacking?
> ...
> Using threads you wouldn't need to do an os.fork(). Simply
> create a new thread using the Python "threading" module
> inside the Apache process to do the unpacking. You probably
> just need to detach the thread so it finishes up properly
> and doesn't need another thread to wait on it to finish.

If you're using a multi-threaded MPM, you might not even want to detach it. It can be useful to let Apache return a "server unavailable" (503) response if all of your threads are busy unzipping files. If you're using a multi-process MPM, you might just do it in the same process to achieve the same effect.

The thread or process won't die just because the client closes the connection. Right away, I'd give them the option: "Thanks for the file! It's being unzipped and processed now. You can trust me and close your browser, or wait for a final confirmation message when I'm done." Then, when the long process is done, write out the "final confirmation message" whether they're connected or not--Apache won't choke on that if they've left.

Robert Brewer
System Architect
Amor Ministries
fumanchu at amor.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20060211/bbd7289d/attachment.html

More information about the Mod_python mailing list