mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Allow start/restart being used inside handlers with block=False
This commit is contained in:
parent
51f88ef1bf
commit
d9cb9c59bf
@ -840,11 +840,17 @@ class Client(Methods, BaseClient):
|
|||||||
self.initialize()
|
self.initialize()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def stop(self):
|
def stop(self, block: bool = True):
|
||||||
"""Stop the Client.
|
"""Stop the Client.
|
||||||
|
|
||||||
This method disconnects the client from Telegram and stops the underlying tasks.
|
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 restarted. It is useful with ``block=False`` in case
|
||||||
|
you want to stop the own client *within* an handler in order not to cause a deadlock.
|
||||||
|
Defaults to True.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
:obj:`Client`: The stopped client itself.
|
:obj:`Client`: The stopped client itself.
|
||||||
|
|
||||||
@ -864,17 +870,29 @@ class Client(Methods, BaseClient):
|
|||||||
|
|
||||||
app.stop()
|
app.stop()
|
||||||
"""
|
"""
|
||||||
|
def do_it():
|
||||||
self.terminate()
|
self.terminate()
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
||||||
|
if block:
|
||||||
|
do_it()
|
||||||
|
else:
|
||||||
|
Thread(target=do_it).start()
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def restart(self):
|
def restart(self, block: bool = True):
|
||||||
"""Restart the Client.
|
"""Restart the Client.
|
||||||
|
|
||||||
This method will first call :meth:`~Client.stop` and then :meth:`~Client.start` in a row in order to restart
|
This method will first call :meth:`~Client.stop` and then :meth:`~Client.start` in a row in order to restart
|
||||||
a client using a single method.
|
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.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
:obj:`Client`: The restarted client itself.
|
:obj:`Client`: The restarted client itself.
|
||||||
|
|
||||||
@ -898,9 +916,15 @@ class Client(Methods, BaseClient):
|
|||||||
|
|
||||||
app.stop()
|
app.stop()
|
||||||
"""
|
"""
|
||||||
|
def do_it():
|
||||||
self.stop()
|
self.stop()
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
|
if block:
|
||||||
|
do_it()
|
||||||
|
else:
|
||||||
|
Thread(target=do_it).start()
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user