diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-03-31 18:25:22 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-03-31 18:25:22 (GMT) |
commit | 8b34b53c52ce604bc48b39f83089cd404201de1b (patch) | |
tree | 7f15c215d673520fb452b7652187448b8119f5f0 /Lib/concurrent | |
parent | 6eeadf0a3efd964837e0a274bf202442facdb617 (diff) | |
parent | f70401e842d120407c5450d0b89cece8616af8e4 (diff) | |
download | cpython-8b34b53c52ce604bc48b39f83089cd404201de1b.zip cpython-8b34b53c52ce604bc48b39f83089cd404201de1b.tar.gz cpython-8b34b53c52ce604bc48b39f83089cd404201de1b.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')
-rw-r--r-- | Lib/concurrent/futures/_base.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/concurrent/futures/_base.py b/Lib/concurrent/futures/_base.py index 3b097b5..88b5fbd 100644 --- a/Lib/concurrent/futures/_base.py +++ b/Lib/concurrent/futures/_base.py @@ -111,12 +111,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) |