Issue I am facing
Hello! I found a strange thing for me. (code below)
I usually run the bot the way app_2 runs (sorry if that's clumsy :) ). But I decided to put the non-asynchronous things in a separate function like in app_1, and the bot stopped responding. In the example below, I moved the building of the bot to a special function, and the bot stopped working.
I found out that the problem happens in Application._update_fetcher in the line update = await self.update_queue.get(). The problem is that update is always successfully queued but never read.
However, the first time it is read normally as long as the queue is not empty (for example, if you timeout before the loop and have time to fill the queue). But when update_queue.qsize() == 0, await just freezes and is no longer executed, even if the queue fills again.
Since I found the bug and fixed it locally, I don't need any help with that, I'm just interested in why this might be happening? Maybe it has something to do with the asynchronous event loop or something like that?
Traceback to the issue
No response
Related part of your code
import asyncio
from telegram.ext.filters import ChatType
from telegram.ext import Application, MessageHandler
# vvv
def create_app_1(token: str):
return Application.builder().token(token).build()
async def run_app_1(app_1: Application):
app_1.add_handler(MessageHandler(ChatType.PRIVATE, send, block=False))
await app_1.initialize()
await app_1.updater.start_polling()
await app_1.start()
print("Bot 1 is running!")
async def run_app_2(token: str):
app_2 = Application.builder().token(token).build()
app_2.add_handler(MessageHandler(ChatType.PRIVATE, send, block=False))
await app_2.initialize()
await app_2.updater.start_polling()
await app_2.start()
print("Bot 2 is running!")
# ^^^
async def send(update, context):
await update.effective_chat.send_message("TEXT")
async def pulling(*coros):
await asyncio.gather(*coros)
while True:
await asyncio.sleep(1)
TOKEN_1 = "123:TOKEN_1"
TOKEN_2 = "321:TOKEN_2"
app_1 = create_app_1(TOKEN_1)
run_coro_1 = run_app_1(app_1)
run_coro_2 = run_app_2(TOKEN_2)
asyncio.run(pulling(run_coro_1, run_coro_2))
Operating System
Ubuntu 20.04
Version of Python, python-telegram-bot & dependencies
python3.8
python-telegram-bot==20.2
nothing else :)
Issue I am facing
Hello! I found a strange thing for me. (code below)
I usually run the bot the way
app_2runs (sorry if that's clumsy :) ). But I decided to put the non-asynchronous things in a separate function like inapp_1, and the bot stopped responding. In the example below, I moved the building of the bot to a special function, and the bot stopped working.I found out that the problem happens in
Application._update_fetcherin the lineupdate = await self.update_queue.get(). The problem is thatupdateis always successfully queued but never read.However, the first time it is read normally as long as the queue is not empty (for example, if you timeout before the loop and have time to fill the queue). But when
update_queue.qsize() == 0,awaitjust freezes and is no longer executed, even if the queue fills again.Since I found the bug and fixed it locally, I don't need any help with that, I'm just interested in why this might be happening? Maybe it has something to do with the asynchronous event loop or something like that?
Traceback to the issue
No response
Related part of your code
Operating System
Ubuntu 20.04
Version of Python, python-telegram-bot & dependencies
python3.8 python-telegram-bot==20.2 nothing else :)