mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 12:51:18 +00:00
Use the current loop instead of the main loop in case there is one available
#482
This commit is contained in:
parent
617f0c9b30
commit
44880f7efe
@ -28,7 +28,7 @@ from pyrogram.methods.utilities import idle as idle_module
|
||||
|
||||
def async_to_sync(obj, name):
|
||||
function = getattr(obj, name)
|
||||
loop = asyncio.get_event_loop()
|
||||
main_loop = asyncio.get_event_loop()
|
||||
|
||||
async def consume_generator(coroutine):
|
||||
return [i async for i in coroutine]
|
||||
@ -37,6 +37,11 @@ def async_to_sync(obj, name):
|
||||
def async_to_sync_wrap(*args, **kwargs):
|
||||
coroutine = function(*args, **kwargs)
|
||||
|
||||
try:
|
||||
loop = asyncio.get_event_loop()
|
||||
except RuntimeError:
|
||||
loop = main_loop
|
||||
|
||||
if loop.is_running():
|
||||
if threading.current_thread() is threading.main_thread():
|
||||
return coroutine
|
||||
|
Loading…
Reference in New Issue
Block a user