stop()

Client.stop()

Stop the Client.

This method disconnects the client from Telegram and stops the underlying tasks.

Parameters:

block (bool, optional) – Blocks the code execution until the client has been stopped. It is useful with block=False in case you want to stop the own client within a handler in order not to cause a deadlock. Defaults to True.

Returns:

Client – The stopped client itself.

Raises:

ConnectionError – In case you try to stop an already stopped client.

Example

from pyrogram import Client

app = Client("my_account")


async def main():
    await app.start()
    ...  # Invoke API methods
    await app.stop()


app.run(main())