Visitar URL original
bpo-31783: Fix a race condition creating workers during shutdown by brianquinlan · Pull Request #13171 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-31783: Fix a race condition while creating workers during interpr…
…eter shutdown
  • Loading branch information
brianquinlan committed May 7, 2019
commit b4222fd0b89d7ad736e8401b97d936087c6aff67
8 changes: 6 additions & 2 deletions Lib/concurrent/futures/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@

_threads_queues = weakref.WeakKeyDictionary()
_shutdown = False
# Lock that ensures that new workers are not created while the interpreter is
# shutting down. Must be held while mutating _threads_queues and _shutdown.
_global_shutdown_lock = threading.Lock()

def _python_exit():
global _shutdown
_shutdown = True
with _global_shutdown_lock:
_shutdown = True
items = list(_threads_queues.items())
for t, q in items:
q.put(None)
Expand Down Expand Up @@ -158,7 +162,7 @@ def submit(*args, **kwargs):
raise TypeError('submit expected at least 1 positional argument, '
'got %d' % (len(args)-1))

with self._shutdown_lock:
with self._shutdown_lock, _global_shutdown_lock:
if self._broken:
raise BrokenThreadPool(self._broken)

Expand Down