Created
April 9, 2021 17:12
-
-
Save piekstra/3b579d8843232d897eca657c1577f5a7 to your computer and use it in GitHub Desktop.
A Windows OS-specific HACK workaround to silence an exception thrown on the asyncio event loop being closed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Windows OS-specific HACK to silence exception thrown on event loop being closed | |
# as part of the asyncio library's proactor | |
# Hack sourced from an issue on the aiohttp library: | |
# https://github.com/aio-libs/aiohttp/issues/4324#issuecomment-733884349 | |
# This assumes you have the asyncio library installed | |
import platform | |
if platform.system() == 'Windows': | |
from functools import wraps | |
from asyncio.proactor_events import _ProactorBasePipeTransport | |
def silence_event_loop_closed(func): | |
@wraps(func) | |
def wrapper(self, *args, **kwargs): | |
try: | |
return func(self, *args, **kwargs) | |
except RuntimeError as e: | |
if str(e) != 'Event loop is closed': | |
raise | |
return wrapper | |
_ProactorBasePipeTransport.__del__ = silence_event_loop_closed(_ProactorBasePipeTransport.__del__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment