From c8f27ee4996b258708d06795854b98ae0accf776 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Tue, 31 Jan 2023 11:09:14 +0000 Subject: [PATCH] IOLoop.current(): create new asyncio loop if not already present --- tornado/ioloop.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tornado/ioloop.py b/tornado/ioloop.py index 8245d34a2..cad985396 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -254,10 +254,13 @@ class IOLoop(Configurable): """ try: loop = asyncio.get_event_loop() - except (RuntimeError, AssertionError): + except RuntimeError: if not instance: return None - raise + # Create a new asyncio event loop for this thread. + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + try: return IOLoop._ioloop_for_asyncio[loop] except KeyError: -- 2.47.2