Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/firebolt/common/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from asyncio import get_event_loop, new_event_loop
from asyncio import get_event_loop, new_event_loop, set_event_loop
from functools import lru_cache, wraps
from typing import TYPE_CHECKING, Any, Callable, Type, TypeVar

Expand Down Expand Up @@ -40,15 +40,12 @@ def fix_url_schema(url: str) -> str:
def async_to_sync(f: Callable) -> Callable:
@wraps(f)
def sync(*args: Any, **kwargs: Any) -> Any:
close = False
try:
loop = get_event_loop()
except RuntimeError:
loop = new_event_loop()
close = True
set_event_loop(loop)
res = loop.run_until_complete(f(*args, **kwargs))
if close:
loop.close()
return res

return sync