Skip to content

Commit

Permalink
fix: get_event_loop - set new loop as current loop in threads (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Jun 1, 2023
1 parent 71c5e40 commit a593037
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions multicall/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ def get_async_w3(w3: Web3) -> Web3:
async_w3s[w3] = async_w3
return async_w3

def get_event_loop() -> asyncio.AbstractEventLoop:
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 await_awaitable(awaitable: Awaitable) -> Any:
return get_event_loop().run_until_complete(awaitable)
Expand Down

0 comments on commit a593037

Please sign in to comment.