diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-03-31 20:23:30 +0200 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-03-31 20:23:30 +0200 |
commit | cac970bac515e6d186b9b23ec4665344373d32ba (patch) | |
tree | e1953e84eafc72384d26b83fe038c3924f2ff87b /Lib/concurrent | |
parent | 2758dc71673cfe5961702954120650c625a8ec87 (diff) | |
download | cpython-cac970bac515e6d186b9b23ec4665344373d32ba.tar.gz |
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 79b91d495f..9f11f6977f 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) |