Run Multiple Asyncio Frameworks, is it possible?
The answer is yes. But it’s not a trivial task. I had this question when I was working on a telegram bot with python telegram bot(PTB) framework, while I also want to run a fastapi server using uvicorn. PTB is built on top of asyncio and if you run Application.run_polling() it will block the event loop. So I had to find a way to let both run without blocking.
Option 1: Embed the other asyncio frameworks in one event loop Actually this is the recommended way to run multiple asyncio (including webserver or another bot), the given example is as follows: