From 62363740c1cc0e137ff4344c3afc3d52e070f200 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Fri, 7 Jul 2023 21:19:18 -0400 Subject: [PATCH] asyncio: Remove atexit hook This hook was added because of an only-in-CI issue, but we have since improved our cleanup of the selector thread. As long as this passes CI, I think we can remove the atexit hook. Fixes #3291 --- tornado/platform/asyncio.py | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/tornado/platform/asyncio.py b/tornado/platform/asyncio.py index 679068e69..32fe860a6 100644 --- a/tornado/platform/asyncio.py +++ b/tornado/platform/asyncio.py @@ -23,7 +23,6 @@ the same event loop. """ import asyncio -import atexit import concurrent.futures import errno import functools @@ -61,31 +60,6 @@ _FileDescriptorLike = Union[int, _HasFileno] _T = TypeVar("_T") -# Collection of selector thread event loops to shut down on exit. -_selector_loops: Set["SelectorThread"] = set() - - -def _atexit_callback() -> None: - for loop in _selector_loops: - with loop._select_cond: - loop._closing_selector = True - loop._select_cond.notify() - try: - loop._waker_w.send(b"a") - except BlockingIOError: - pass - if loop._thread is not None: - # If we don't join our (daemon) thread here, we may get a deadlock - # during interpreter shutdown. I don't really understand why. This - # deadlock happens every time in CI (both travis and appveyor) but - # I've never been able to reproduce locally. - loop._thread.join() - _selector_loops.clear() - - -atexit.register(_atexit_callback) - - class BaseAsyncIOLoop(IOLoop): def initialize( # type: ignore self, asyncio_loop: asyncio.AbstractEventLoop, **kwargs: Any @@ -480,7 +454,6 @@ class SelectorThread: self._waker_r, self._waker_w = socket.socketpair() self._waker_r.setblocking(False) self._waker_w.setblocking(False) - _selector_loops.add(self) self.add_reader(self._waker_r, self._consume_waker) def close(self) -> None: @@ -492,7 +465,6 @@ class SelectorThread: self._wake_selector() if self._thread is not None: self._thread.join() - _selector_loops.discard(self) self.remove_reader(self._waker_r) self._waker_r.close() self._waker_w.close() -- 2.47.2