Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0473fe7

Browse files
gvanrossummiss-islington
authored andcommittedSep 30, 2022
pythonGH-96827: Don't touch closed loops from executor threads (pythonGH-96837)
* When chaining futures, skip callback if loop closed. * When shutting down an executor, don't wake a closed loop. (cherry picked from commit e9d6376) Co-authored-by: Guido van Rossum <[email protected]>
1 parent 6d7dbcc commit 0473fe7

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed
 

‎Lib/asyncio/base_events.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,11 @@ async def shutdown_default_executor(self):
573573
def _do_shutdown(self, future):
574574
try:
575575
self._default_executor.shutdown(wait=True)
576-
self.call_soon_threadsafe(future.set_result, None)
576+
if not self.is_closed():
577+
self.call_soon_threadsafe(future.set_result, None)
577578
except Exception as ex:
578-
self.call_soon_threadsafe(future.set_exception, ex)
579+
if not self.is_closed():
580+
self.call_soon_threadsafe(future.set_exception, ex)
579581

580582
def _check_running(self):
581583
if self.is_running():

‎Lib/asyncio/futures.py

+2
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ def _call_set_state(source):
396396
if dest_loop is None or dest_loop is source_loop:
397397
_set_state(destination, source)
398398
else:
399+
if dest_loop.is_closed():
400+
return
399401
dest_loop.call_soon_threadsafe(_set_state, destination, source)
400402

401403
destination.add_done_callback(_call_check_cancel)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Avoid spurious tracebacks from :mod:`asyncio` when default executor cleanup is delayed until after the event loop is closed (e.g. as the result of a keyboard interrupt).

0 commit comments

Comments
 (0)
Please sign in to comment.