From: Thomas Kluyver Date: Tue, 31 Jan 2023 11:09:14 +0000 (+0000) Subject: IOLoop.current(): create new asyncio loop if not already present X-Git-Tag: v6.3.0b1~8^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c8f27ee4996b258708d06795854b98ae0accf776;p=thirdparty%2Ftornado.git IOLoop.current(): create new asyncio loop if not already present --- 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: