[3.10] bpo-45021: Fix a hang in forked children (GH-28007) (GH-28480) · python/cpython@d0d83a9

Original file line numberDiff line numberDiff line change

@@ -36,6 +36,12 @@ def _python_exit():

3636

# See bpo-39812 for context.

3737

threading._register_atexit(_python_exit)

3838
39+

# At fork, reinitialize the `_global_shutdown_lock` lock in the child process

40+

if hasattr(os, 'register_at_fork'):

41+

os.register_at_fork(before=_global_shutdown_lock.acquire,

42+

after_in_child=_global_shutdown_lock._at_fork_reinit,

43+

after_in_parent=_global_shutdown_lock.release)

44+
3945
4046

class _WorkItem(object):

4147

def __init__(self, future, fn, args, kwargs):