del IOLoop._ioloop_for_asyncio[loop]
except KeyError:
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]
+ raise RuntimeError(
+ f"IOLoop {existing_loop} already associated with asyncio loop {asyncio_loop}"
+ )
+
IOLoop._ioloop_for_asyncio[asyncio_loop] = self
self._thread_identity = 0
asyncio_loop = asyncio.new_event_loop()
loop = IOLoop(asyncio_loop=asyncio_loop, make_current=False)
assert loop.asyncio_loop is asyncio_loop # type: ignore
+ with self.assertRaises(RuntimeError):
+ # Can't register two IOLoops with the same asyncio_loop
+ IOLoop(asyncio_loop=asyncio_loop, make_current=False)
loop.close()