]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
IOLoop.current(): create new asyncio loop if not already present
authorThomas Kluyver <thomas@kluyver.me.uk>
Tue, 31 Jan 2023 11:09:14 +0000 (11:09 +0000)
committerThomas Kluyver <thomas@kluyver.me.uk>
Thu, 9 Feb 2023 08:38:59 +0000 (08:38 +0000)
tornado/ioloop.py

index 8245d34a2a7c3951440fa924472f1b92f3593c14..cad98539671247133c333e4f90ddaf029962aa3b 100644 (file)
@@ -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: