Start background thread only if it was None

This commit is contained in:
Lonami Exo 2017-09-22 13:13:41 +02:00
parent d8bf8bb2eb
commit 6d60e83adc

View File

@ -1041,11 +1041,12 @@ class TelegramClient(TelegramBareClient):
def _set_connected_and_authorized(self): def _set_connected_and_authorized(self):
self._authorized = True self._authorized = True
self._recv_thread = Thread( if self._recv_thread is None:
name='ReadThread', daemon=True, self._recv_thread = Thread(
target=self._recv_thread_impl name='ReadThread', daemon=True,
) target=self._recv_thread_impl
self._recv_thread.start() )
self._recv_thread.start()
# By using this approach, another thread will be # By using this approach, another thread will be
# created and started upon connection to constantly read # created and started upon connection to constantly read
@ -1075,7 +1076,8 @@ class TelegramClient(TelegramBareClient):
except Exception as e: except Exception as e:
# Unknown exception, pass it to the main thread # Unknown exception, pass it to the main thread
self.updates.set_error(e) self.updates.set_error(e)
self._recv_thread = None break
return
self._recv_thread = None
# endregion # endregion