idle()

static Client.idle()

Block the main script execution until a signal is received.

This static method will run an infinite loop in order to block the main script execution and prevent it from exiting while having client(s) that are still running in the background.

It is useful for event-driven application only, that are, applications which react upon incoming Telegram updates through handlers, rather than executing a set of methods sequentially.

The way Pyrogram works, it will keep your handlers in a pool of worker threads, which are executed concurrently outside the main thread; calling idle() will ensure the client(s) will be kept alive by not letting the main script to end, until you decide to quit.

Once a signal is received (e.g.: from CTRL+C) the inner infinite loop will break and your main script will continue. Don’t forget to call stop() for each running client before the script ends.

Parameters

stop_signals (tuple, optional) – Iterable containing signals the signal handler will listen to. Defaults to (SIGINT, SIGTERM, SIGABRT).

Example

from pyrogram import Client

app1 = Client("account1")
app2 = Client("account2")
app3 = Client("account3")

...  # Set handlers up

app1.start()
app2.start()
app3.start()

Client.idle()

app1.stop()
app2.stop()
app3.stop()