diff --git a/devicehive/device_hive.py b/devicehive/device_hive.py index f723b01..e5cbb95 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_alive_timeout = options.pop('transport_alive_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_alive_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..7d57882 100644 --- a/devicehive/transports/transport.py +++ b/devicehive/transports/transport.py @@ -108,6 +108,9 @@ def disconnect(self): 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