mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +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
1 changed files with 6 additions and 1 deletions
|
|
@ -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 a new issue