Don't start the updates thread until signed in

This commit is contained in:
Lonami Exo
2017-05-19 21:44:50 +02:00
parent 2f2ee15efd
commit 3c3946e6f1
2 changed files with 22 additions and 7 deletions

View File

@@ -118,6 +118,10 @@ class TelegramClient:
# although many other options are available!
self.dc_options = result.dc_options
# Once we know we're authorized, we can setup the ping thread
if self.is_user_authorized():
self.sender.setup_ping_thread()
return True
except RPCError as error:
print('Could not stabilise initial connection: {}'.format(error))
@@ -236,6 +240,12 @@ class TelegramClient:
self.session.user = result.user
self.session.save()
# If we want the connection to stay alive for a long time, we need
# to start the pings thread once we're already authorized and not
# before to avoid the updates thread trying to read anything while
# we haven't yet connected.
self.sender.setup_ping_thread()
return True
def sign_up(self, phone_number, code, first_name, last_name=''):