[python-win32] Q: daemon spawn from within apache cgi blocks parent process

Tim Roberts timr at probo.com
Tue May 24 18:48:58 CEST 2005


On Tue, 24 May 2005 00:43:32 +0200, <replytodirk at web.de> wrote:

>I want to create a daemon process from within a python cgi script running on
>apache/win32. This daemon's lifetime is longer than that of the creating cgi
>script - of course, because the script starts the daemon, writes some html
>code to stdout and then exits. This simple task kept me busy for weeks!
>...
>Does anybody have an idea what goes wrong here? Is there any connection
>between a parent and a child process which has to be released before the
>processes can die independently? Are there any Apache-specific things to
>handle when spawning processes?
>  
>

Yes.  A CGI connection is considered "open" until the stdout file handle 
closes.  Your spawned process is inheriting all of your handles, so 
stdout remains open until the spawned process closes it.  Normally, that 
only happens when the process exits.

You have a couple of choices.  If you are using CreateProess, you can 
specify that handles are not to be inherited (it's the 5th parameter to 
CreateProcess API; I don't know where it lives in PyWin32).  Or, you can 
have the daemon close the stdout handle as soon as it starts.  Either 
solution should solve your problem.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-win32 mailing list