[Zope] Re: zope fork in external method - mysql connection dropped

Dieter Maurer dieter at handshake.de
Tue Oct 17 15:58:32 EDT 2006


Daniel Lopez wrote at 2006-10-16 13:31 -0700:
>I made one tweak to the double-fork procedure, adding a waitpid call in the 
>grandparent process (the original zope thread) before it returns out of the 
>external method... the code then looked something like:
>
>[...prefork code up to here...]
>pid1 = os.fork()
>if pid1 > 0:
>    #grandparent waits for its child before returning
>    os.waitpid(pid1, 0)
>    return RESPONSE.redirect("wait_page")
>pid2 = os.fork()
>os.setsid()
>if pid2 > 0:
>    #child quits, orphaning grandchild
>    sys.exit(0)
>[...grandchild-only code after here...]
>
>The waitpid call seems to be preventing the zombies... this is good! 
>(though if you find something bad about this approach, please do speak up)
>
>But in the process, a new bug was created, having to do with the MySQL 
>connection.  I now receive a "Lost connection to MySQL server during 
>query" error in what appears to be a final db flush from the grandparent's 
>publish function (ZPublisher.Publish, line 104).  The good news is that 
>the grandchild continues to do it's work, but the bad news is that the 
>user receives an error page instead of the redirect to the "wait_page".

Maybe, the MySQL client library installed an "atexit" hook that closes
the database connection.

You may try "sys._exit(0)" (instead of "sys.exit(0)") to finish
the child. "_exit" is for purposes when you do not want standard
exit handling (such as flushing buffers and calling "atexit" hooks).



-- 
Dieter


More information about the Zope mailing list