[issue25920] PyOS_AfterFork should reset socketmodule's lock

STINNER Victor report at bugs.python.org
Thu May 14 19:42:29 EDT 2020


STINNER Victor <vstinner at python.org> added the comment:

> Maybe instead of releasing the lock in the forked child process, we should try to acquire the lock in the os.fork() implementation, and then release it?

In bpo-40089, I added _PyThread_at_fork_reinit() for this purpose: reinitialize a lock after a fork to unlocked state. Internally, it leaks memory on purpose and then create a new lock, since there is no portable way to reset a lock after fork.

The problem is how to register netdb_lock of Modules/socketmodule.c into a list of locks which should be reinitialized at fork, or maybe how to register a C callback called at fork. There is a *Python* API to register a callback after a fork: os.register_at_fork().

See also the meta-issue bpo-6721: "Locks in the standard library should be sanitized on fork".

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue25920>
_______________________________________


More information about the Python-bugs-list mailing list