From 99d76012eab2466a76b718b4778891971f6788f0 Mon Sep 17 00:00:00 2001 From: Andrey Viktorov Date: Mon, 3 Jun 2019 22:42:19 +0300 Subject: [PATCH 1/2] Added cancel pending tasks coro --- hbmqtt/client.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hbmqtt/client.py b/hbmqtt/client.py index 78df853..77a494d 100644 --- a/hbmqtt/client.py +++ b/hbmqtt/client.py @@ -164,7 +164,7 @@ class MQTTClient: This method is a *coroutine*. """ - + yield from self.cancel_tasks() if self.session.transitions.is_connected(): if not self._disconnect_task.done(): self._disconnect_task.cancel() @@ -175,6 +175,19 @@ class MQTTClient: else: self.logger.warning("Client session is not currently connected, ignoring call") + @asyncio.coroutine + def cancel_tasks(self): + """ + Before disconnection need to cancel all pending tasks + :return: + """ + try: + while True: + task: asyncio.Future = self.client_tasks.pop() + task.cancel() + except IndexError as err: + pass + @asyncio.coroutine def reconnect(self, cleansession=None): """ From 8a20cbe0c7542b73e05541d46332c6aa54c6a971 Mon Sep 17 00:00:00 2001 From: andvikt <39195436+andvikt@users.noreply.github.com> Date: Tue, 4 Jun 2019 10:17:17 +0300 Subject: [PATCH 2/2] Update client.py python 34 support --- hbmqtt/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hbmqtt/client.py b/hbmqtt/client.py index 77a494d..77cf442 100644 --- a/hbmqtt/client.py +++ b/hbmqtt/client.py @@ -183,7 +183,7 @@ class MQTTClient: """ try: while True: - task: asyncio.Future = self.client_tasks.pop() + task = self.client_tasks.pop() task.cancel() except IndexError as err: pass