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 e9d63760fe)

Co-authored-by: Guido van Rossum <guido@python.org>
This commit is contained in:
Miss Islington (bot) 2022-09-30 13:23:33 -07:00 committed by GitHub
parent 3124618fd5
commit 95609525de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View file

@ -577,9 +577,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():