Skip to content

Commit

Permalink
get_event_loop() fixes
Browse files Browse the repository at this point in the history
- Obeys event loop policy
- Consistent on multiple platforms
  • Loading branch information
TheSpookyCat committed May 25, 2023
1 parent 7c9fcd9 commit 3c51839
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions pypresence/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,12 @@ def get_ipc_path(pipe=None):


def get_event_loop(force_fresh=False):
if sys.platform in ('linux', 'darwin'):
if force_fresh:
return asyncio.new_event_loop()
try:
loop = asyncio.get_running_loop()
except RuntimeError:
return asyncio.new_event_loop()
if loop.is_closed():
return asyncio.new_event_loop()
return loop
elif sys.platform == 'win32':
if force_fresh:
return asyncio.ProactorEventLoop()
loop = asyncio.get_event_loop()
if isinstance(loop, asyncio.ProactorEventLoop) and not loop.is_closed():
return loop
return asyncio.ProactorEventLoop()
if force_fresh:
return asyncio.new_event_loop()
try:
running = asyncio.get_running_loop()
except RuntimeError:
return asyncio.new_event_loop()
if running.is_closed():
return asyncio.new_event_loop()
return running

0 comments on commit 3c51839

Please sign in to comment.