From dab0a05f16641200c22e4368c9db9cc76c6bcdcb Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:08:01 +0200 Subject: [PATCH] Move idle() and signal_handler() definitions near stop() --- pyrogram/client/client.py | 44 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) 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.