summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
authorAntoine Pitrou <pitrou@free.fr>2017-05-28 12:02:26 (GMT)
committerGitHub <noreply@github.com>2017-05-28 12:02:26 (GMT)
commit4a8bcdf79cdb3684743fe1268de62ee88bada439 (patch)
treeb2a35e7b3035cdaa5a8fe5bdcba81ca177d5686c /Lib/threading.py
parent0aa0a06e8b719533aefd175a5716f1698f474052 (diff)
downloadcpython-4a8bcdf79cdb3684743fe1268de62ee88bada439.zip
cpython-4a8bcdf79cdb3684743fe1268de62ee88bada439.tar.gz
cpython-4a8bcdf79cdb3684743fe1268de62ee88bada439.tar.bz2
bpo-16500: Use register_at_fork() in the threading module (#1843)
* bpo-16500: Use register_at_fork() in the threading module * Update comment at top of _after_fork()
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 0b59464..2eaf49a 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -1,5 +1,6 @@
"""Thread module emulating a subset of Java's threading model."""
+import os as _os
import sys as _sys
import _thread
@@ -943,6 +944,7 @@ class Thread:
exc_tb.tb_frame.f_code.co_name)), file=self._stderr)
exc_tb = exc_tb.tb_next
print(("%s: %s" % (exc_type, exc_value)), file=self._stderr)
+ self._stderr.flush()
# Make sure that exc_tb gets deleted since it is a memory
# hog; deleting everything else is just for thoroughness
finally:
@@ -1319,10 +1321,9 @@ except ImportError:
def _after_fork():
- # This function is called by Python/ceval.c:PyEval_ReInitThreads which
- # is called from PyOS_AfterFork_Child. Here we cleanup threading module
- # state that should not exist after a fork.
-
+ """
+ Cleanup threading module state that should not exist after a fork.
+ """
# Reset _active_limbo_lock, in case we forked while the lock was held
# by another (non-forked) thread. http://bugs.python.org/issue874900
global _active_limbo_lock, _main_thread
@@ -1356,3 +1357,7 @@ def _after_fork():
_active.clear()
_active.update(new_active)
assert len(_active) == 1
+
+
+if hasattr(_os, "fork"):
+ _os.register_at_fork(_after_fork, when="child")