mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
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.
This commit is contained in:
parent
b298b395e8
commit
a8cae4071c
2 changed files with 10 additions and 1 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue