diff options
author | Victor Stinner <vstinner@python.org> | 2023-09-06 13:57:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-06 13:57:01 (GMT) |
commit | a8cae4071c795e55be46e339eda37e241fa0d7f8 (patch) | |
tree | a91d0b46c6492d7fb090a1d5430acd95db27f979 /Lib/concurrent | |
parent | b298b395e8ab1725c4f0dd736155b8c818664d42 (diff) | |
download | cpython-a8cae4071c795e55be46e339eda37e241fa0d7f8.zip cpython-a8cae4071c795e55be46e339eda37e241fa0d7f8.tar.gz cpython-a8cae4071c795e55be46e339eda37e241fa0d7f8.tar.bz2 |
gh-107219: Fix concurrent.futures terminate_broken() (#108974)
Fix a race condition in _ExecutorManagerThread.terminate_broken():
ignore the InvalidStateError on future.set_exception(). It can happen
if the future is cancelled before the caller.
Moreover, test_crash_big_data() now waits explicitly until the
executor completes.
Diffstat (limited to 'Lib/concurrent')
-rw-r--r-- | Lib/concurrent/futures/process.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py index 301207f..9933d3d 100644 --- a/Lib/concurrent/futures/process.py +++ b/Lib/concurrent/futures/process.py @@ -489,7 +489,14 @@ class _ExecutorManagerThread(threading.Thread): # Mark pending tasks as failed. for work_id, work_item in self.pending_work_items.items(): - work_item.future.set_exception(bpe) + try: + work_item.future.set_exception(bpe) + except _base.InvalidStateError as exc: + # set_exception() fails if the future is cancelled: ignore it. + # Trying to check if the future is cancelled before calling + # set_exception() would leave a race condition if the future is + # cancelled betwen the check and set_exception(). + pass # Delete references to object. See issue16284 del work_item self.pending_work_items.clear() |