[New-bugs-announce] [issue16500] Add an 'afterfork' module

Christian Heimes 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.

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.

----------
assignee: christian.heimes
components: Extension Modules, Interpreter Core
keywords: needs review
messages: 175878
nosy: christian.heimes
priority: normal
severity: normal
status: open
title: Add an 'afterfork' module
type: enhancement
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16500>
_______________________________________


More information about the New-bugs-announce mailing list