Skip to content

Commit 21ce3b3

Browse files
author
John Doe
committed
Merge branch 'master' of github.com:xloem/async_to_sync
2 parents 08cd3dc + d5b1cc3 commit 21ce3b3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

async_to_sync/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ def get_default_event_loop():
99
global _loop, _thread
1010
if _thread is None:
1111
if _loop is None:
12-
_loop = asyncio.get_event_loop()
12+
try:
13+
_loop = asyncio.get_event_loop()
14+
except RuntimeError:
15+
_loop = asyncio.new_event_loop()
16+
asyncio.set_event_loop(_loop)
1317
if not _loop.is_running():
1418
_thread = threading.Thread(
1519
target=_loop.run_forever,
@@ -18,6 +22,7 @@ def get_default_event_loop():
1822
return _loop
1923

2024
def set_default_event_loop(loop):
25+
global _loop
2126
stop()
2227
_loop = loop
2328

0 commit comments

Comments
 (0)