]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
make existing_loop check atomic 3164/head
authorThomas Grainger <tagrain@gmail.com>
Tue, 21 Jun 2022 07:41:38 +0000 (08:41 +0100)
committerGitHub <noreply@github.com>
Tue, 21 Jun 2022 07:41:38 +0000 (08:41 +0100)
tornado/platform/asyncio.py

index ad1bde093bff613b1840d4e7a22e95e794a92ea8..909cd7877691643defaa8ea6c3c3b4e300a90662 100644 (file)
@@ -131,14 +131,12 @@ class BaseAsyncIOLoop(IOLoop):
                     pass
 
         # Make sure we don't already have an IOLoop for this asyncio loop
-        if asyncio_loop in IOLoop._ioloop_for_asyncio:
-            existing_loop = IOLoop._ioloop_for_asyncio[asyncio_loop]
+        existing_loop = IOLoop._ioloop_for_asyncio.setdefault(asyncio_loop, self)
+        if existing_loop is not self:
             raise RuntimeError(
                 f"IOLoop {existing_loop} already associated with asyncio loop {asyncio_loop}"
             )
 
-        IOLoop._ioloop_for_asyncio[asyncio_loop] = self
-
         self._thread_identity = 0
 
         super().initialize(**kwargs)