[Python] How to run a Telegram bot polling asynchronously without blocking the main...

Discussão em 'Python' iniciado por Stack, Dezembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to run a Telegram bot using the python-telegram-bot library (version >= 20) in asynchronous mode. The problem is that when I start the polling, the whole application blocks. I have tried using both threading and asyncio.create_task() to prevent the polling from blocking the main application, but I keep encountering various errors.

    Error:

    RuntimeError: This event loop is already running<br>
    RuntimeError: Cannot close a running event loop


    I have tried various solutions without success. Has anyone experienced this with the library and can suggest a definitive solution to run the polling asynchronously without blocking the main application?

    Continue reading...

Compartilhe esta Página