Rename ._connect_lock to ._reconnect_lock

This commit is contained in:
Lonami Exo 2017-09-30 18:25:09 +02:00
parent 671ac1cdb7
commit b6bc9ac39b

View File

@ -104,7 +104,7 @@ class TelegramBareClient:
# Two threads may be calling reconnect() when the connection is lost, # Two threads may be calling reconnect() when the connection is lost,
# we only want one to actually perform the reconnection. # we only want one to actually perform the reconnection.
self._connect_lock = Lock() self._reconnect_lock = Lock()
# Cache "exported" sessions as 'dc_id: Session' not to recreate # Cache "exported" sessions as 'dc_id: Session' not to recreate
# them all the time since generating a new key is a relatively # them all the time since generating a new key is a relatively
@ -287,7 +287,7 @@ class TelegramBareClient:
""" """
if new_dc is None: if new_dc is None:
# Assume we are disconnected due to some error, so connect again # Assume we are disconnected due to some error, so connect again
with self._connect_lock: with self._reconnect_lock:
# Another thread may have connected again, so check that first # Another thread may have connected again, so check that first
if not self.is_connected(): if not self.is_connected():
return self.connect() return self.connect()
@ -428,8 +428,8 @@ class TelegramBareClient:
# thread reading or if the server disconnected us and we're trying # thread reading or if the server disconnected us and we're trying
# to reconnect. This is because the read thread may either be # to reconnect. This is because the read thread may either be
# locked also trying to reconnect or we may be said thread already. # locked also trying to reconnect or we may be said thread already.
call_receive = not on_main_thread or \ call_receive = not on_main_thread or self._recv_thread is None \
self._recv_thread is None or self._connect_lock.locked() or self._reconnect_lock.locked()
try: try:
for _ in range(retries): for _ in range(retries):
result = self._invoke(sender, call_receive, *requests) result = self._invoke(sender, call_receive, *requests)
@ -481,7 +481,7 @@ class TelegramBareClient:
pass # We will just retry pass # We will just retry
except ConnectionResetError: except ConnectionResetError:
if self._connect_lock.locked(): if self._reconnect_lock.locked():
# We are connecting and we don't want to reconnect there... # We are connecting and we don't want to reconnect there...
raise raise