English
Open in Telegram

Thread application = ApplicationBuilder().token(BOT_TOKEN).defaults(my_defaults).build()

16 messages · –
N
application = ApplicationBuilder().token(BOT_TOKEN).defaults(my_defaults).build() I have this code and all i have full async await function all over my handers, but i found when one user send somethigns and the handler function taks 10 seconds to finish this the bot doesnot send respond to any other user, what mistakes i am doing here?
  1. N
    Wiki of python-telegram-bot - Category Concepts & Important Elements Concurrency in PTB
  2. P
    Opening files using`with open` is not async, that's why your bot stops. For opening files in async, try to use aiofiles Or create a separate function and run it using asyncio.to_thread
    1. N
      so you say i will make another normal function where will open file and send but how this normal fun can have await send_file ? i am confusd can u pls clarify what is best idea?
      1. A
        import asyncio def read_file(path): with open(path, "rb") as f: return f.read() async def send_file(update, context): data = await asyncio.to_thread(read_file, "file.pdf") await update.message.reply_document( document=data )
        1. N
          actually i have not any proper understanding of using async like this so when suppose need this file on /need_file so first i will make fun to handle this /need_file in this function i will call the await send_file ? will it works like this? so still this use the with open :- you say this was blocking my function so how this time will it work parallel?
            1. N
              So i can probably understand in the command handler same function, i can add this below there async with aiofiles.open("large_file.txt", mode="r") as f: data = await f.read() return data
        2. م
          How Can I Make My text Like This? I mean With A Code?
          1. R
            I moved this discussion to the off-topic group.
          2. N
            Wiki of python-telegram-bot - Category Code Snippets Message Formatting (bold, italic, code, ...)
            1. L
              ohhh I thought he meant in telegram without a bot
>>>> telegram.Bot()>>> telegram.Bot()@pythontelegrambotgroup · group · Tech
9 911members60writing in 30 days
Venue feed Open in Telegram

An open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · Index limits · Remove a page · Catalog · Search · How we count