summaryrefslogtreecommitdiffstats
path: root/Lib/concurrent/futures
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-03-31 18:23:30 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-03-31 18:23:30 (GMT)
commitf70401e842d120407c5450d0b89cece8616af8e4 (patch)
tree28d58598132a50abf42600af358a764de5246568 /Lib/concurrent/futures
parent317075de2981c9283e7af7bcf727ef8ae8ee4f4e (diff)
downloadcpython-f70401e842d120407c5450d0b89cece8616af8e4.zip
cpython-f70401e842d120407c5450d0b89cece8616af8e4.tar.gz
cpython-f70401e842d120407c5450d0b89cece8616af8e4.tar.bz2
Issue #14406: Fix a race condition when using `concurrent.futures.wait(return_when=ALL_COMPLETED)`.
Patch by Matt Joiner.
Diffstat (limited to 'Lib/concurrent/futures')
-rw-r--r--Lib/concurrent/futures/_base.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/concurrent/futures/_base.py b/Lib/concurrent/futures/_base.py
index 79b91d4..9f11f69 100644
--- a/Lib/concurrent/futures/_base.py
+++ b/Lib/concurrent/futures/_base.py
@@ -112,12 +112,14 @@ class _AllCompletedWaiter(_Waiter):
def __init__(self, num_pending_calls, stop_on_exception):
self.num_pending_calls = num_pending_calls
self.stop_on_exception = stop_on_exception
+ self.lock = threading.Lock()
super().__init__()
def _decrement_pending_calls(self):
- self.num_pending_calls -= 1
- if not self.num_pending_calls:
- self.event.set()
+ with self.lock:
+ self.num_pending_calls -= 1
+ if not self.num_pending_calls:
+ self.event.set()
def add_result(self, future):
super().add_result(future)