From 90cd751bb6cc3d7a2fd0a9c6aec6659298cf33ff Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 1 Sep 2017 18:46:36 +0200 Subject: [PATCH 1/2] bpo-31326: ProcessPoolExecutor waits for the call queue thread concurrent.futures.ProcessPoolExecutor.shutdown() now explicitly closes the call queue. Moreover, shutdown(wait=True) now also join the call queue thread, to prevent leaking a dangling thread. --- Lib/concurrent/futures/process.py | 3 +++ .../next/Library/2017-09-01-18-48-06.bpo-31326.TB05tV.rst | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2017-09-01-18-48-06.bpo-31326.TB05tV.rst diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py index 8f1d714193ab799..8811bc4f19b0569 100644 --- a/Lib/concurrent/futures/process.py +++ b/Lib/concurrent/futures/process.py @@ -495,6 +495,9 @@ def shutdown(self, wait=True): # To reduce the risk of opening too many files, remove references to # objects that use file descriptors. self._queue_management_thread = None + self._call_queue.close() + if wait: + self._call_queue.join_thread() self._call_queue = None self._result_queue = None self._processes = None diff --git a/Misc/NEWS.d/next/Library/2017-09-01-18-48-06.bpo-31326.TB05tV.rst b/Misc/NEWS.d/next/Library/2017-09-01-18-48-06.bpo-31326.TB05tV.rst new file mode 100644 index 000000000000000..ea0ff2b45807a71 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2017-09-01-18-48-06.bpo-31326.TB05tV.rst @@ -0,0 +1,3 @@ +concurrent.futures.ProcessPoolExecutor.shutdown() now explicitly closes the +call queue. Moreover, shutdown(wait=True) now also join the call queue +thread, to prevent leaking a dangling thread. From 707343b24321313152fe129ed947eef54752ab2a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 1 Sep 2017 19:02:20 +0200 Subject: [PATCH 2/2] Fix for shutdown() being called twice. --- Lib/concurrent/futures/process.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py index 8811bc4f19b0569..ee2318522ecc66b 100644 --- a/Lib/concurrent/futures/process.py +++ b/Lib/concurrent/futures/process.py @@ -495,10 +495,11 @@ def shutdown(self, wait=True): # To reduce the risk of opening too many files, remove references to # objects that use file descriptors. self._queue_management_thread = None - self._call_queue.close() - if wait: - self._call_queue.join_thread() - self._call_queue = None + if self._call_queue is not None: + self._call_queue.close() + if wait: + self._call_queue.join_thread() + self._call_queue = None self._result_queue = None self._processes = None shutdown.__doc__ = _base.Executor.shutdown.__doc__