From b4222fd0b89d7ad736e8401b97d936087c6aff67 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Tue, 7 May 2019 15:22:31 -0400 Subject: [PATCH 1/2] bpo-31783: Fix a race condition while creating workers during interpreter shutdown --- Lib/concurrent/futures/thread.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/concurrent/futures/thread.py b/Lib/concurrent/futures/thread.py index 2af31a106dd914..6aab7c8ee2e3bf 100644 --- a/Lib/concurrent/futures/thread.py +++ b/Lib/concurrent/futures/thread.py @@ -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) @@ -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) From e1f0027127dd434d432055c8095cc4aa1567231c Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" Date: Tue, 7 May 2019 19:25:56 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2019-05-07-19-25-55.bpo-31783.lgLo69.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2019-05-07-19-25-55.bpo-31783.lgLo69.rst diff --git a/Misc/NEWS.d/next/Library/2019-05-07-19-25-55.bpo-31783.lgLo69.rst b/Misc/NEWS.d/next/Library/2019-05-07-19-25-55.bpo-31783.lgLo69.rst new file mode 100644 index 00000000000000..a261e59ccfecd8 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-05-07-19-25-55.bpo-31783.lgLo69.rst @@ -0,0 +1 @@ +Fix race condition in ThreadPoolExecutor when worker threads are created during interpreter shutdown. \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy