diff --git a/pyrogram/dispatcher.py b/pyrogram/dispatcher.py index c5f166d5..b4ec7673 100644 --- a/pyrogram/dispatcher.py +++ b/pyrogram/dispatcher.py @@ -95,7 +95,12 @@ class Dispatcher: def __init__(self, client: "pyrogram.Client"): self.client = client - self.loop = asyncio.get_event_loop() + try: + loop = asyncio.get_event_loop() + except RuntimeError: + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + self.loop = loop self.handler_worker_tasks = [] self.locks_list = [] diff --git a/pyrogram/sync.py b/pyrogram/sync.py index 0a3feeca..6aae972f 100644 --- a/pyrogram/sync.py +++ b/pyrogram/sync.py @@ -29,7 +29,11 @@ from pyrogram.methods.utilities import idle as idle_module, compose as compose_m def async_to_sync(obj, name): function = getattr(obj, name) - main_loop = asyncio.get_event_loop() + try: + main_loop = asyncio.get_event_loop() + except RuntimeError: + main_loop = asyncio.new_event_loop() + asyncio.set_event_loop(main_loop) def async_to_sync_gen(agen, loop, is_main_thread): async def anext(agen):