diff --git a/multicall/utils.py b/multicall/utils.py index 635da8f2..3889ff8a 100644 --- a/multicall/utils.py +++ b/multicall/utils.py @@ -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)