Visitar URL original
Use the current loop instead of the main loop in case there is one av… · pythonfansx/pyrogram@44880f7 · GitHub
Skip to content

Commit 44880f7

Browse files
committed
Use the current loop instead of the main loop in case there is one available
#482
1 parent 617f0c9 commit 44880f7

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎pyrogram/sync.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
def async_to_sync(obj, name):
3030
function = getattr(obj, name)
31-
loop = asyncio.get_event_loop()
31+
main_loop = asyncio.get_event_loop()
3232

3333
async def consume_generator(coroutine):
3434
return [i async for i in coroutine]
@@ -37,6 +37,11 @@ async def consume_generator(coroutine):
3737
def async_to_sync_wrap(*args, **kwargs):
3838
coroutine = function(*args, **kwargs)
3939

40+
try:
41+
loop = asyncio.get_event_loop()
42+
except RuntimeError:
43+
loop = main_loop
44+
4045
if loop.is_running():
4146
if threading.current_thread() is threading.main_thread():
4247
return coroutine

0 commit comments

Comments
 (0)