This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author christian.heimes
Recipients christian.heimes
Date 2012-11-18.15:20:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1353252005.31.0.454056781872.issue16500@psf.upfronthosting.co.za>
In-reply-to
Content
I propose the addition of an 'afterfork' module. The module shall fulfill a similar task as the 'atexit' module except that it handles process forks instead of process shutdown.

The 'afterfork' module shall allow libraries to register callbacks that are executed on fork() inside the child process and as soon as possible. Python already has a function that must be called by C code: PyOS_AfterFork(). The 'afterfork' callbacks are called as the last step in PyOS_AfterFork().

Use case example:
The tempfile module has a specialized RNG that re-initialized the RNG after fork() by comparing os.getpid() to an instance variable every time the RNG is accessed. The check can be replaced with an afterfork callback.

Open questions:
How should the afterfork() module handle exceptions that are raised by callbacks?

Implementation:
I'm going to use as much code from atexitmodule.c as possible. I'm going to copy common code to a template file and include the template from atexitmodule.c and afterforkmodule.c with some preprocessor tricks.
History
Date User Action Args
2012-11-18 15:20:05christian.heimessetrecipients: + christian.heimes
2012-11-18 15:20:05christian.heimessetmessageid: <1353252005.31.0.454056781872.issue16500@psf.upfronthosting.co.za>
2012-11-18 15:20:04christian.heimeslinkissue16500 messages
2012-11-18 15:20:03christian.heimescreate