bpo-45021: Fix a hang in forked children (GH-28007)

_global_shutdown_lock should be reinitialized in forked children
This commit is contained in:
nullptr 2021-09-20 20:30:19 +02:00 committed by GitHub
parent 9510e6f3c7
commit 0bfa1106ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View file

@ -36,6 +36,12 @@ def _python_exit():
# See bpo-39812 for context.
threading._register_atexit(_python_exit)
# At fork, reinitialize the `_global_shutdown_lock` lock in the child process
if hasattr(os, 'register_at_fork'):
os.register_at_fork(before=_global_shutdown_lock.acquire,
after_in_child=_global_shutdown_lock._at_fork_reinit,
after_in_parent=_global_shutdown_lock.release)
class _WorkItem(object):
def __init__(self, future, fn, args, kwargs):