From 66c1a1e23f85a03ccd6605d39412ad283c2ce889 Mon Sep 17 00:00:00 2001 From: Igor Panteleev Date: Thu, 14 Sep 2017 18:41:57 +0300 Subject: [PATCH 1/3] change thread join to infinite loop --- devicehive/device_hive.py | 4 +++- devicehive/transports/transport.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/devicehive/device_hive.py b/devicehive/device_hive.py index f723b01..20841c2 100644 --- a/devicehive/device_hive.py +++ b/devicehive/device_hive.py @@ -39,6 +39,7 @@ def connect(self, transport_url, **options): connect_timeout = options.pop('connect_timeout', 30) max_num_connect = options.pop('max_num_connect', 10) connect_interval = options.pop('connect_interval', 1) + transport_timeout = options.pop('transport_timeout', 0.01) self._api_handler_options['auth'] = auth self._init_transport() connect_time = time.time() @@ -47,7 +48,8 @@ def connect(self, transport_url, **options): if self._transport.connected: self._transport.disconnect() self._transport.connect(transport_url, **options) - self._transport.join() + while self._transport.is_alive(): + time.sleep(transport_timeout) exception_info = self._transport.exception_info if exception_info and not isinstance(exception_info[1], self._transport.error): diff --git a/devicehive/transports/transport.py b/devicehive/transports/transport.py index 5327d92..7301cb2 100644 --- a/devicehive/transports/transport.py +++ b/devicehive/transports/transport.py @@ -105,8 +105,8 @@ def disconnect(self): self._ensure_connected() self._connected = False - def join(self, timeout=None): - self._connection_thread.join(timeout) + def is_alive(self): + return self._connection_thread.is_alive() def send_request(self, request_id, action, request, **params): raise NotImplementedError From ffb832673a02d194bedf7bd9355a7ca7313909c8 Mon Sep 17 00:00:00 2001 From: Igor Panteleev Date: Fri, 15 Sep 2017 18:31:42 +0300 Subject: [PATCH 2/3] return "join" method back --- devicehive/transports/transport.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/devicehive/transports/transport.py b/devicehive/transports/transport.py index 7301cb2..7d57882 100644 --- a/devicehive/transports/transport.py +++ b/devicehive/transports/transport.py @@ -105,6 +105,9 @@ def disconnect(self): self._ensure_connected() self._connected = False + def join(self, timeout=None): + self._connection_thread.join(timeout) + def is_alive(self): return self._connection_thread.is_alive() From 46c275fab4f19cd327337c0742074d972484841a Mon Sep 17 00:00:00 2001 From: Igor Panteleev Date: Fri, 15 Sep 2017 18:38:29 +0300 Subject: [PATCH 3/3] rename parametr --- devicehive/device_hive.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devicehive/device_hive.py b/devicehive/device_hive.py index 20841c2..e5cbb95 100644 --- a/devicehive/device_hive.py +++ b/devicehive/device_hive.py @@ -39,7 +39,7 @@ def connect(self, transport_url, **options): connect_timeout = options.pop('connect_timeout', 30) max_num_connect = options.pop('max_num_connect', 10) connect_interval = options.pop('connect_interval', 1) - transport_timeout = options.pop('transport_timeout', 0.01) + transport_alive_timeout = options.pop('transport_alive_timeout', 0.01) self._api_handler_options['auth'] = auth self._init_transport() connect_time = time.time() @@ -49,7 +49,7 @@ def connect(self, transport_url, **options): self._transport.disconnect() self._transport.connect(transport_url, **options) while self._transport.is_alive(): - time.sleep(transport_timeout) + time.sleep(transport_alive_timeout) exception_info = self._transport.exception_info if exception_info and not isinstance(exception_info[1], self._transport.error):