summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-11-16 15:17:17 (GMT)
committerGitHub <noreply@github.com>2020-11-16 15:17:17 (GMT)
commitcf70854f10096446115408b5a94030b30594a459 (patch)
tree0a5b1f816e5007f58e8de4ecdedaaf9e7e4ed783 /Lib/threading.py
parent7c4d8fa82aae98f2d638be68f21e9524a92a38e6 (diff)
downloadcpython-cf70854f10096446115408b5a94030b30594a459.zip
cpython-cf70854f10096446115408b5a94030b30594a459.tar.gz
cpython-cf70854f10096446115408b5a94030b30594a459.tar.bz2
bpo-42350: Fix Thread._reset_internal_locks() (GH-23268)
Fix the threading.Thread class at fork: do nothing if the thread is already stopped (ex: fork called at Python exit). Previously, an error was logged in the child process. (cherry picked from commit 5909a494cd3ba43143b28bd439773ed85a485dfc) Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index ab29db7..d96d99a 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -826,8 +826,12 @@ class Thread:
# they may be in an invalid state leading to a deadlock or crash.
self._started._at_fork_reinit()
if is_alive:
- self._tstate_lock._at_fork_reinit()
- self._tstate_lock.acquire()
+ # bpo-42350: If the fork happens when the thread is already stopped
+ # (ex: after threading._shutdown() has been called), _tstate_lock
+ # is None. Do nothing in this case.
+ if self._tstate_lock is not None:
+ self._tstate_lock._at_fork_reinit()
+ self._tstate_lock.acquire()
else:
# The thread isn't alive after fork: it doesn't have a tstate
# anymore.