summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-09-30 20:25:06 (GMT)
committerGitHub <noreply@github.com>2022-09-30 20:25:06 (GMT)
commita5c503f296a104d8b5b2e917a2f1ef71be888e1b (patch)
tree436ef6997f69fd020d1f49b72f09a7318ca5b748 /Lib/asyncio
parent6d7dbcc0b365c9f227a4c299211c068b3da54a90 (diff)
downloadcpython-a5c503f296a104d8b5b2e917a2f1ef71be888e1b.zip
cpython-a5c503f296a104d8b5b2e917a2f1ef71be888e1b.tar.gz
cpython-a5c503f296a104d8b5b2e917a2f1ef71be888e1b.tar.bz2
GH-96827: Don't touch closed loops from executor threads (GH-96837)
* 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>
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/base_events.py6
-rw-r--r--Lib/asyncio/futures.py2
2 files changed, 6 insertions, 2 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index ea10399..1cc26ee 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -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():
diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py
index 48a32f8..5d00ab4 100644
--- a/Lib/asyncio/futures.py
+++ b/Lib/asyncio/futures.py
@@ -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)