The Wayback Machine - https://web.archive.org/web/20240108231835/https://github.com/pyrogram/pyrogram/issues/663
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot stuck when all workers are busy uploading files with a progress function #663

Closed
3 tasks done
xsolinsx opened this issue Apr 5, 2021 · 1 comment
Closed
3 tasks done

Comments

@xsolinsx
Copy link
Contributor

xsolinsx commented Apr 5, 2021

Checklist

  • I am sure the error is coming from Pyrogram's code and not elsewhere.
  • I have searched in the issue tracker for similar bug reports, including closed ones.
  • I ran pip3 install -U https://github.com/pyrogram/pyrogram/archive/master.zip and reproduced the issue using the latest development version.

Description

The bot will get stuck when all workers are busy uploading a file ONLY if a progress function is specified, I tried with 2 and 4 workers (respectively with 2 and 4 files) and I got stuck anyway.
It seems the progress function is not even called as I cannot see the prints on the console.
Below the code you will find the files I used as example, as you can see they are very small and so they should be uploaded almost immediately.
If the files are uploaded one at a time or without the progress function specified the upload goes well and everything is okay.
P.S. I am on Windows 10 x64, tried with Python 3.7 and 3.9

from pyrogram import Client, idle
from pyrogram.filters import command, regex
from pyrogram.types import (
    CallbackQuery,
    InlineKeyboardButton,
    InlineKeyboardMarkup,
    Message,
)

api_id = ""
api_hash = ""
token = ""
APP = Client("bug_test", api_id, api_hash, bot_token=token, workers=2)


def FProgress(current, total):
    print(current, total)


@APP.on_callback_query(regex(r"^up"))
def CbQryUpload(_, cb_qry: CallbackQuery):
    cb_qry.answer("ok")
    if cb_qry.data == "up1":
        cb_qry.message.reply_document("f1.txt", progress=FProgress)
    elif cb_qry.data == "up2":
        cb_qry.message.reply_document("f2.txt", progress=FProgress)


@APP.on_message(command("keyboard"))
def CmdKeyboard(_, msg: Message):
    kybrd = InlineKeyboardMarkup(
        [[InlineKeyboardButton("up1", "up1")], [InlineKeyboardButton("up2", "up2")]]
    )
    msg.reply_text("test simultaneous upload", reply_markup=kybrd)


APP.start()
idle()
APP.stop()

f1.txt
f2.txt

Steps to Reproduce

  1. Execute the code above.
  2. Send the /keyboard command to the bot.
  3. Quickly click both buttons.
  4. The bot gets stuck.
@delivrance
Copy link
Member

Must be a thread deadlock happening in the executor. Fast "workaround" (quoted because it's something you should've done from the beginning), use asyncio (i.e. add async/await keywords and adjust the code accordingly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants