mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Issue #14406: Fix a race condition when using concurrent.futures.wait(return_when=ALL_COMPLETED)
.
Patch by Matt Joiner.
This commit is contained in:
commit
8b34b53c52
3 changed files with 25 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue