# 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()
with self.assertRaises(BrokenProcessPool):
list(executor.map(_crash_with_data, [data] * 10))
+ executor.shutdown(wait=True)
+
create_executor_tests(globals(), ExecutorDeadlockTest,
executor_mixins=(ProcessPoolForkMixin,