From: Min RK Date: Fri, 3 Sep 2021 11:40:25 +0000 (+0200) Subject: swallow "Event loop is closed" from selector thread X-Git-Tag: v6.2.0b1~25^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3059%2Fhead;p=thirdparty%2Ftornado.git swallow "Event loop is closed" from selector thread same catch as in `add_callback` for the same reasons - the selector thread may race with an asyncio_loop.close in the main thread seen running tests with pytest-asyncio --- diff --git a/tornado/platform/asyncio.py b/tornado/platform/asyncio.py index 5e9c776d0..d312c3d90 100644 --- a/tornado/platform/asyncio.py +++ b/tornado/platform/asyncio.py @@ -576,7 +576,21 @@ class AddThreadSelectorEventLoop(asyncio.AbstractEventLoop): raise else: raise - self._real_loop.call_soon_threadsafe(self._handle_select, rs, ws) + + try: + self._real_loop.call_soon_threadsafe(self._handle_select, rs, ws) + except RuntimeError: + # "Event loop is closed". Swallow the exception for + # consistency with PollIOLoop (and logical consistency + # with the fact that we can't guarantee that an + # add_callback that completes without error will + # eventually execute). + pass + except AttributeError: + # ProactorEventLoop may raise this instead of RuntimeError + # if call_soon_threadsafe races with a call to close(). + # Swallow it too for consistency. + pass def _handle_select( self, rs: List["_FileDescriptorLike"], ws: List["_FileDescriptorLike"]