[mod_python] Re: forks, daemons and other beasts

Daniel Nogradi nogradi at gmail.com
Mon Feb 13 15:44:52 EST 2006


> (Uh... Just one observation: They UPLOAD a ZIP file, and you expect the 
> unpacking to take longer than that?)

The unpacking itself doesn't take that long, but until the unpacked files reach their final destination (directories, databases, etc) will take quite some time as they have to be processed in some way. But I agree, uploading takes much longer, but I would like to make the waiting time for the users as short as possible, and in principle the unpacking/processing/etc can be done after they receive an acknowledgement page.

> You might consider using the latest mod_python 3.2.7 modification that 
> supports file "streaming". You can unpack the ZIP while it's being 
> uploaded. This also prevents using TEMP space. And when the upload is 
> ready, the files are there as well. I tested this method for uploading 
> multi-gigabyte TAR files.
> 
> The trick is to add a file callback to the FieldStorage object. I have 
> attached a sample upload PSP script that just counts bytes. I'll leave 
> it up to your imagination to feed the data into a ZipFile object.
> 
> Attempting to fork extra threads or processes from within an Apache 
> instance will bring you lots of troubles - and you never know what 
> happens in future versions.
> 
> --
> Mike Looijmans
> 
> 

Thanks a lot for the code, I didn't even think about such an approach, this would be the best of course.


> For example, if you have this script, /tmp/foo.py:
> 
>     ############################################################
>     # /tmp/foo.py
> 
>     import signal
>     import time
> 
>     # ignore the TERM signal, so if apache kills the child process
>     # that forked me I won't die.
>     signal.signal(signal.SIGTERM, signal.SIG_IGN)
> 
>     # Your Code Here!
>     # for this demo we'll sleep, so you have time to stop apache and
>     # see this is still running
>     time.sleep(30)
> 
>     # some output to prove we ran
>     print "hello, world"
> 
>     #
>     ############################################################
> 
> 
> Then in your handler:
> 
>     os.system('python /tmp/foo.py >& /tmp/foo.log &')
> 
> 
> Daniel Popowich
> ---------------
> http://home.comcast.net/~d.popowich/mpservlets/


I'm not sure I understand this. AFAIK both os.spawn* and os.system start a brand new process, with the only difference being how command line arguments are handled. Or not?



More information about the Mod_python mailing list