DEV Community

Parvat R
Parvat R

Posted on

New to Pyrogram? Take a look here.

Define a client in different way:


import pyrogram

client = pyrogram.Client("Session-Name")
Enter fullscreen mode Exit fullscreen mode


Enter fullscreen mode Exit fullscreen mode

You can get your api_id, api_hash from telegram. And, you can get the token from @botfather

Do long time process, without disturbing the bot

import _thread

def some_long_process(param1, param2):
    # do something that takes long time
    param2.reply_text('Process Over.')

def do_big(_c, message):
    _thread.start_new_thread(some_long_process, (_c, message))
Enter fullscreen mode Exit fullscreen mode

You can pass on the client and the message parameter to some function, which takes a long time to complete, and has to notify the user when it completes. During this process, some times the bot might stop responding to other users, or become slow.

So, use _thread module to start a new thread which runs in background without disturbing your bot, and making it faster to the core.

Top comments (0)