From c9cd79cb0566e9f21a9e813e374a96cc606516d2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jun 2018 15:49:56 +0200 Subject: [PATCH] Fix merge mess with duplicated idle() methods --- pyrogram/client/client.py | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 23c2abcc..2025c524 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -265,7 +265,7 @@ class Client(Methods, BaseClient): self.is_started = False await self.session.stop() - def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)): + async 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. @@ -275,6 +275,7 @@ class Client(Methods, BaseClient): Defaults to (SIGINT, SIGTERM, SIGABRT). """ def signal_handler(*args): + log.info("Stop signal received ({}). Exiting...".format(args[0])) self.is_idle = False for s in stop_signals: @@ -283,9 +284,9 @@ class Client(Methods, BaseClient): self.is_idle = True while self.is_idle: - time.sleep(1) + await asyncio.sleep(1) - self.stop() + await self.stop() def run(self): """Use this method to automatically start and idle a Client. @@ -800,29 +801,6 @@ class Client(Methods, BaseClient): log.info("UpdatesWorkerTask stopped") - def signal_handler(self, *args): - log.info("Stop signal received ({}). Exiting...".format(args[0])) - self.is_idle = False - - async 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: - await asyncio.sleep(1) - - await self.stop() - async def send(self, data: Object): """Use this method to send Raw Function queries.