From 515263aa9548f9e180e2f2d3eef7a885d5a88514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Mon, 18 Jan 2016 02:38:41 +0200 Subject: [PATCH] Made thread joins interruptible by specifying a timeout (fixes #25) --- CHANGES | 6 ++++++ concurrent/futures/process.py | 6 +++--- concurrent/futures/thread.py | 4 ++-- setup.py | 9 ++++++++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 86fcfa6..d18b204 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +3.0.4 +===== + +- Fixed inability to forcibly terminate the process if there are pending workers + + 3.0.3 ===== diff --git a/concurrent/futures/process.py b/concurrent/futures/process.py index 665da8e..812552b 100644 --- a/concurrent/futures/process.py +++ b/concurrent/futures/process.py @@ -77,7 +77,7 @@ def _python_exit(): for t, q in items: q.put(None) for t, q in items: - t.join() + t.join(sys.maxint) # Controls how many more calls than processes will be queued in the call queue. # A smaller number will mean that processes spend more time idle waiting for @@ -232,7 +232,7 @@ def _queue_management_worker(executor_reference, # some multiprocessing.Queue methods may deadlock on Mac OS # X. for p in processes: - p.join() + p.join(sys.maxint) call_queue.close() return del executor @@ -347,7 +347,7 @@ class ProcessPoolExecutor(_base.Executor): # Wake up queue management thread self._result_queue.put(None) if wait: - self._queue_management_thread.join() + self._queue_management_thread.join(sys.maxint) # To reduce the risk of openning too many files, remove references to # objects that use file descriptors. self._queue_management_thread = None diff --git a/concurrent/futures/thread.py b/concurrent/futures/thread.py index cee65d0..85ab4b7 100644 --- a/concurrent/futures/thread.py +++ b/concurrent/futures/thread.py @@ -36,7 +36,7 @@ def _python_exit(): for t, q in items: q.put(None) for t, q in items: - t.join() + t.join(sys.maxint) atexit.register(_python_exit) @@ -130,5 +130,5 @@ class ThreadPoolExecutor(_base.Executor): self._work_queue.put(None) if wait: for t in self._threads: - t.join() + t.join(sys.maxint) shutdown.__doc__ = _base.Executor.shutdown.__doc__ diff --git a/setup.py b/setup.py index 0e4524b..dfad9f4 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,11 @@ #!/usr/bin/env python +from warnings import warn +import sys + +if sys.version_info[0] > 2: + warn('This backport is meant only for Python 2.\n' + 'Python 3 users do not need it, as the concurrent.futures ' + 'package is available in the standard library.') extras = {} try: @@ -8,7 +15,7 @@ except ImportError: from distutils.core import setup setup(name='futures', - version='3.0.3', + version='3.0.4', description='Backport of the concurrent.futures package from Python 3.2', author='Brian Quinlan', author_email='brian@sweetapp.com',