Closed brostosjoined closed 1 year ago
The only reason this should happen is if someone has set a loop that doesn't support pipes as the default. Other loops are not guaranteed to be supported.
See: https://docs.python.org/3.6/library/asyncio-eventloops.html
On Windows, only sockets are supported (ex: pipes are not supported).
I'm happy to look at this PR again if the existing code causes problems but all of my tests show the function is stable.
Here are some few modification
def get_event_loop(force_fresh=False):
loop = asyncio.ProactorEventLoop() if sys.platform == 'win32' else asyncio.new_event_loop()
if force_fresh:
return loop
try:
running = asyncio.get_running_loop()
except RuntimeError:
return loop
if running.is_closed():
return loop
else:
if sys.platform in ('linux', 'darwin'):
return running
if sys.platform == 'win32':
if isinstance(running, asyncio.ProactorEventLoop):
return running
else:
return loop
In case where there is a running loop but the loop is not Proactor Event loop.