summaryrefslogtreecommitdiffstats
path: root/Lib/concurrent/futures/thread.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-09-20 18:54:24 (GMT)
committerGitHub <noreply@github.com>2021-09-20 18:54:24 (GMT)
commitb06c3b364720ce8e8dfb74dfa24434e067ac89ba (patch)
tree96b09241eeac18358104f98d2665d01f13d560c5 /Lib/concurrent/futures/thread.py
parent04dea46dde25d58f242171181805f0e71a042963 (diff)
downloadcpython-b06c3b364720ce8e8dfb74dfa24434e067ac89ba.zip
cpython-b06c3b364720ce8e8dfb74dfa24434e067ac89ba.tar.gz
cpython-b06c3b364720ce8e8dfb74dfa24434e067ac89ba.tar.bz2
[3.9] bpo-45021: Fix a hang in forked children (GH-28007) (GH-28481)
_global_shutdown_lock should be reinitialized in forked children (cherry picked from commit 0bfa1106acfcddc03590e1f5d6789dbad3affe70) Co-authored-by: nullptr <3621629+0x0L@users.noreply.github.com> Automerge-Triggered-By: GH:gpshead
Diffstat (limited to 'Lib/concurrent/futures/thread.py')
-rw-r--r--Lib/concurrent/futures/thread.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/concurrent/futures/thread.py b/Lib/concurrent/futures/thread.py
index b7a2cac..51c942f 100644
--- a/Lib/concurrent/futures/thread.py
+++ b/Lib/concurrent/futures/thread.py
@@ -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):