diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 5e6324fc..2cd31dc9 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -285,6 +285,28 @@ class Client(Methods, BaseClient): self.is_started = False self.session.stop() + def signal_handler(self, *args): + self.is_idle = False + + def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)): + """Blocks the program execution until one of the signals are received, + then gently stop the Client by closing the underlying connection. + + Args: + stop_signals (``tuple``, *optional*): + Iterable containing signals the signal handler will listen to. + Defaults to (SIGINT, SIGTERM, SIGABRT). + """ + for s in stop_signals: + signal(s, self.signal_handler) + + self.is_idle = True + + while self.is_idle: + time.sleep(1) + + self.stop() + def add_handler(self, handler, group: int = 0): """Use this method to register an update handler. @@ -790,28 +812,6 @@ class Client(Methods, BaseClient): log.debug("{} stopped".format(name)) - def signal_handler(self, *args): - self.is_idle = False - - def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)): - """Blocks the program execution until one of the signals are received, - then gently stop the Client by closing the underlying connection. - - Args: - stop_signals (``tuple``, *optional*): - Iterable containing signals the signal handler will listen to. - Defaults to (SIGINT, SIGTERM, SIGABRT). - """ - for s in stop_signals: - signal(s, self.signal_handler) - - self.is_idle = True - - while self.is_idle: - time.sleep(1) - - self.stop() - def send(self, data: Object): """Use this method to send Raw Function queries.