mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-11 03:56:36 +03:00
Fix MainThread would lock when reconnecting
This is because it was thinking that the ReadThread would be ready to read the result, but actually, this thread is also locked trying to reconnect at the same time
This commit is contained in:
parent
9dfb5d493c
commit
bfa3001f87
|
@ -245,19 +245,19 @@ class TelegramClient(TelegramBareClient):
|
||||||
"""
|
"""
|
||||||
# This is only valid when the read thread is reconnecting,
|
# This is only valid when the read thread is reconnecting,
|
||||||
# that is, the connection lock is locked.
|
# that is, the connection lock is locked.
|
||||||
on_read_thread = self._on_read_thread()
|
if self._on_read_thread() and not self._connect_lock.locked():
|
||||||
if on_read_thread and not self._connect_lock.locked():
|
|
||||||
raise AssertionError('Cannot invoke requests from the ReadThread')
|
raise AssertionError('Cannot invoke requests from the ReadThread')
|
||||||
|
|
||||||
self.updates.check_error()
|
self.updates.check_error()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Users may call this method from within some update handler.
|
# We should call receive from this thread if there's no background
|
||||||
# If this is the case, then the thread invoking the request
|
# thread reading or if the server disconnected us and we're trying
|
||||||
# will be the one which should be reading (but is invoking the
|
# to reconnect. This is because the read thread may either be
|
||||||
# request) thus not being available to read it "in the background"
|
# locked also trying to reconnect or we may be said thread already.
|
||||||
# and it's needed to call receive.
|
call_receive = \
|
||||||
call_receive = on_read_thread or self._recv_thread is None
|
self._recv_thread is None or self._connect_lock.locked()
|
||||||
|
|
||||||
return super().invoke(
|
return super().invoke(
|
||||||
request, call_receive=call_receive,
|
request, call_receive=call_receive,
|
||||||
retries=kwargs.get('retries', 5)
|
retries=kwargs.get('retries', 5)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user