2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 05:18:10 +00:00

Make start and stop methods return self to make chaining possible

Suggestion by @CharlesBachman in Telegram
This commit is contained in:
Dan 2018-12-15 09:50:35 +01:00
parent 6a9c7312cc
commit 001a067d82

View File

@ -198,10 +198,9 @@ class Client(Methods, BaseClient):
self.dispatcher = Dispatcher(self, workers) self.dispatcher = Dispatcher(self, workers)
def __enter__(self): def __enter__(self):
self.start() return self.start()
return self
def __exit__(self, exc_type, exc_val, exc_tb): def __exit__(self, *args):
self.stop() self.stop()
@property @property
@ -294,6 +293,8 @@ class Client(Methods, BaseClient):
mimetypes.init() mimetypes.init()
Syncer.add(self) Syncer.add(self)
return self
def stop(self): def stop(self):
"""Use this method to manually stop the Client. """Use this method to manually stop the Client.
Requires no parameters. Requires no parameters.
@ -331,6 +332,8 @@ class Client(Methods, BaseClient):
self.is_started = False self.is_started = False
self.session.stop() self.session.stop()
return self
def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)): def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)):
"""Blocks the program execution until one of the signals are received, """Blocks the program execution until one of the signals are received,
then gently stop the Client by closing the underlying connection. then gently stop the Client by closing the underlying connection.