[New-bugs-announce] [issue16500] Add an 'afterfork' module
report at bugs.python.org
Sun Nov 18 16:20:05 CET 2012
New submission from Christian Heimes:
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.
How should the afterfork() module handle exceptions that are raised by callbacks?
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.
components: Extension Modules, Interpreter Core
keywords: needs review
title: Add an 'afterfork' module
versions: Python 3.4
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce