Skip to content

Commit

Permalink
Merge pull request #3295 from bdarnell/remove-asyncio-atexit
Browse files Browse the repository at this point in the history
asyncio: Remove atexit hook
  • Loading branch information
bdarnell committed Jul 8, 2023
2 parents 34673bf + 6236374 commit 559f94a
Showing 1 changed file with 0 additions and 28 deletions.
28 changes: 0 additions & 28 deletions tornado/platform/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"""

import asyncio
import atexit
import concurrent.futures
import errno
import functools
Expand Down Expand Up @@ -61,31 +60,6 @@ def fileno(self) -> int:
_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
Expand Down Expand Up @@ -480,7 +454,6 @@ async def thread_manager_anext() -> None:
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:
Expand All @@ -492,7 +465,6 @@ def close(self) -> None:
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()
Expand Down

0 comments on commit 559f94a

Please sign in to comment.