]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-96827: Don't touch closed loops from executor threads (GH-96837)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 30 Sep 2022 20:25:06 +0000 (13:25 -0700)
committerGitHub <noreply@github.com>
Fri, 30 Sep 2022 20:25:06 +0000 (13:25 -0700)
* When chaining futures, skip callback if loop closed.
* When shutting down an executor, don't wake a closed loop.
(cherry picked from commit e9d63760fea8748638f6e495b5b07bd1805c9591)

Co-authored-by: Guido van Rossum <guido@python.org>
Lib/asyncio/base_events.py
Lib/asyncio/futures.py
Misc/NEWS.d/next/Library/2022-09-30-15-56-20.gh-issue-96827.lzy1iw.rst [new file with mode: 0644]

index ea10399b94131013778bdd18ef57fb9e17977cb4..1cc26ee7ccf06a794e78b08bc57a2fa7427762d6 100644 (file)
@@ -573,9 +573,11 @@ class BaseEventLoop(events.AbstractEventLoop):
     def _do_shutdown(self, future):
         try:
             self._default_executor.shutdown(wait=True)
-            self.call_soon_threadsafe(future.set_result, None)
+            if not self.is_closed():
+                self.call_soon_threadsafe(future.set_result, None)
         except Exception as ex:
-            self.call_soon_threadsafe(future.set_exception, ex)
+            if not self.is_closed():
+                self.call_soon_threadsafe(future.set_exception, ex)
 
     def _check_running(self):
         if self.is_running():
index 48a32f868385c42da0e2608a5fc46d06a26ede38..5d00ab4c8d3119bd4c2da81a1e90996f5da2af0c 100644 (file)
@@ -396,6 +396,8 @@ def _chain_future(source, destination):
         if dest_loop is None or dest_loop is source_loop:
             _set_state(destination, source)
         else:
+            if dest_loop.is_closed():
+                return
             dest_loop.call_soon_threadsafe(_set_state, destination, source)
 
     destination.add_done_callback(_call_check_cancel)
diff --git a/Misc/NEWS.d/next/Library/2022-09-30-15-56-20.gh-issue-96827.lzy1iw.rst b/Misc/NEWS.d/next/Library/2022-09-30-15-56-20.gh-issue-96827.lzy1iw.rst
new file mode 100644 (file)
index 0000000..159ab32
--- /dev/null
@@ -0,0 +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).