summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
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 7dae77d..7b3d63d 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -844,8 +844,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.