Skip to content

Commit

Permalink
fix: get_event_loop - set new loop as current loop in threads (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler committed Jun 1, 2023
1 parent 0c2ed02 commit b5bdcc6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions a_sync/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

def get_event_loop() -> asyncio.BaseEventLoop:
try:
return asyncio.get_event_loop()
loop = asyncio.get_event_loop()
except RuntimeError as e: # Necessary for use with multi-threaded applications.
if not str(e).startswith("There is no current event loop in thread"):
raise e
return asyncio.new_event_loop()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
return loop

def _validate_wrapped_fn(fn: Callable) -> None:
"""Ensures 'fn' is an appropriate function for wrapping with a_sync."""
Expand Down

0 comments on commit b5bdcc6

Please sign in to comment.