1 parent 617f0c9 commit 44880f7Copy full SHA for 44880f7
1 file changed
pyrogram/sync.py
@@ -28,7 +28,7 @@
28
29
def async_to_sync(obj, name):
30
function = getattr(obj, name)
31
- loop = asyncio.get_event_loop()
+ main_loop = asyncio.get_event_loop()
32
33
async def consume_generator(coroutine):
34
return [i async for i in coroutine]
@@ -37,6 +37,11 @@ async def consume_generator(coroutine):
37
def async_to_sync_wrap(*args, **kwargs):
38
coroutine = function(*args, **kwargs)
39
40
+ try:
41
+ loop = asyncio.get_event_loop()
42
+ except RuntimeError:
43
+ loop = main_loop
44
+
45
if loop.is_running():
46
if threading.current_thread() is threading.main_thread():
47
return coroutine
0 commit comments