restart()

Client.restart()

Restart the Client.

This method will first call stop() and then start() in a row in order to restart a client using a single method.

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

  • clear_handlers (bool, optional) – Clear the already existing handlers on restart the client. Default to False.

Returns:

Client – The restarted client itself.

Raises:

ConnectionError – In case you try to restart a stopped Client.

Example

import asyncio

from pyrogram import Client


async def main():
    app = Client("my_account")

    await app.start()
    ...  # Invoke API methods
    await app.restart()
    ...  # Invoke other API methods
    await app.stop()

asyncio.run(main())