[mod_python] Re: forks, daemons and other beasts

Daniel Nogradi nogradi at gmail.com
Sat Feb 11 18:24:20 EST 2006


> >>>>> Anyway, I have the feeling that there must be a more sane and
> >>>>> probably
> >>>>> safe way of achieving what I would like by a much simpler method.
> >>>>>
> >>>>> Any ideas?
> >>>>
> >>>> A quick one.
> >>>>
> >>>> Run a small separate daemon process which embeds an  XML-RPC
> >>>> server and have your web pages use XML-RPC to call that daemon
> >>>> process to trigger off the task. The daemon process can still fork
> >>>> exec
> >>>> as necessary.
> >>>>
> >>>> This way you eliminate a fork in Apache child process which may be
> >>>> problematic because of the socket connections etc that are
> >>>> inherited.
> >>>
> >>> Well, that still looks like to me that I'm shooting a bird with a
> >>> cannon. The reason is that I need to do something really simple:
> >>> users
> >>> upload a zip file (remember my questions about the zipfile
> >>> module? :))
> >>> 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.
> >>
> >> 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?
> >
> > Hmmmmm, what do you mean exactly? When I do an os.fork the whole
> > apache forks, you mean that I should start a brand new thread, outside
> > of apache?
>
> 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.
>
> Sorry, can't give an example right now as trying to rebuild OS on one
> of my
> machines.

Good luck! I'll look into threading in the meantime.



More information about the Mod_python mailing list