From: Thomas Grainger Date: Tue, 21 Jun 2022 07:41:38 +0000 (+0100) Subject: make existing_loop check atomic X-Git-Tag: v6.2.0~2^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F3164%2Fhead;p=thirdparty%2Ftornado.git make existing_loop check atomic --- diff --git a/tornado/platform/asyncio.py b/tornado/platform/asyncio.py index ad1bde093..909cd7877 100644 --- a/tornado/platform/asyncio.py +++ b/tornado/platform/asyncio.py @@ -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)