[Python] DeprecationWarning: There is no current event loop loop = asyncio.get_event_loop()

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Telegram Forwarder BOT i'm trying to use from Github, already downgraded from 3.13 Python to 3.10 but problem still persists. Please help

    import asyncio
    import os
    import signal
    import sys

    from source.core.Bot import Bot
    from source.utils.Console import Terminal
    from source.utils.Constants import SESSION_FOLDER_PATH, RESOURCE_FILE_PATH, MEDIA_FOLDER_PATH

    console = Terminal.console

    #TODO Add documentation
    #TODO Add logging
    async def shutdown(loop, signal=None):
    if signal:
    print(f"Received exit signal {signal.name}...")
    tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]

    print(f"Cancelling {len(tasks)} tasks...")
    [task.cancel() for task in tasks]

    await asyncio.gather(*tasks, return_exceptions=True)
    loop.stop()


    def main():
    os.makedirs(RESOURCE_FILE_PATH, exist_ok=True)
    os.makedirs(MEDIA_FOLDER_PATH, exist_ok=True)
    os.makedirs(SESSION_FOLDER_PATH, exist_ok=True)
    bot = Bot()
    try:
    loop = asyncio.get_event_loop()
    if sys.platform != 'win32':
    signals = (signal.SIGINT, signal.SIGTERM)
    for s in signals:
    loop.add_signal_handler(s, lambda a=s: asyncio.create_task(shutdown(loop, signal=s)))
    loop.run_until_complete(bot.start())
    except Exception as e:
    console.print(f"[bold red]Error:[/bold red] {e}")
    finally:
    loop.close()


    if __name__ == "__main__":
    main()



    That is the code, but I keep getting

    Users\USER\Telegram-Forwarder-Bot\main.py:32: DeprecationWarning: There is no current event loop
    loop = asyncio.get_event_loop()
    No credentials found. Please add credentials first.
    Error: asyncio.run() cannot be called from a running event loop
    sys:1: RuntimeWarning: coroutine 'Application.run_async' was never awaited
    RuntimeWarning: Enable tracemalloc to get the object allocation traceback


    Whenever I try to run it

    tried some solutions I saw on here, but not pointing at the exact solution of the code

    Continue reading...

Compartilhe esta Página