mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Merger 65032 to py3k
This commit is contained in:
parent
e921e02a2e
commit
a851397ddc
3 changed files with 130 additions and 1 deletions
|
@ -783,6 +783,37 @@ except ImportError:
|
|||
from _threading_local import local
|
||||
|
||||
|
||||
def _after_fork():
|
||||
# This function is called by Python/ceval.c:PyEval_ReInitThreads which
|
||||
# is called from PyOS_AfterFork. Here we 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
|
||||
_active_limbo_lock = _allocate_lock()
|
||||
|
||||
# fork() only copied the current thread; clear references to others.
|
||||
new_active = {}
|
||||
current = current_thread()
|
||||
with _active_limbo_lock:
|
||||
for ident, thread in _active.items():
|
||||
if thread is current:
|
||||
# There is only one active thread.
|
||||
new_active[ident] = thread
|
||||
else:
|
||||
# All the others are already stopped.
|
||||
# We don't call _Thread__stop() because it tries to acquire
|
||||
# thread._Thread__block which could also have been held while
|
||||
# we forked.
|
||||
thread._Thread__stopped = True
|
||||
|
||||
_limbo.clear()
|
||||
_active.clear()
|
||||
_active.update(new_active)
|
||||
assert len(_active) == 1
|
||||
|
||||
|
||||
# Self-test code
|
||||
|
||||
def _test():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue