mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-11 09:03:09 +03:00
Support invoking requests from within the ReadThread (fixes #226)
This commit is contained in:
parent
fe86b88bef
commit
a38381665c
|
@ -2,6 +2,7 @@ import os
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from mimetypes import guess_type
|
from mimetypes import guess_type
|
||||||
from threading import RLock, Thread
|
from threading import RLock, Thread
|
||||||
|
import threading
|
||||||
|
|
||||||
from . import TelegramBareClient
|
from . import TelegramBareClient
|
||||||
from . import helpers as utils
|
from . import helpers as utils
|
||||||
|
@ -207,10 +208,16 @@ class TelegramClient(TelegramBareClient):
|
||||||
try:
|
try:
|
||||||
self._lock.acquire()
|
self._lock.acquire()
|
||||||
|
|
||||||
|
# Users may call this method from within some update handler.
|
||||||
|
# If this is the case, then the thread invoking the request
|
||||||
|
# will be the one which should be reading (but is invoking the
|
||||||
|
# request) thus not being available to read it "in the background"
|
||||||
|
# and it's needed to call receive.
|
||||||
|
call_receive = self._recv_thread is None or \
|
||||||
|
threading.get_ident() == self._recv_thread.ident
|
||||||
|
|
||||||
# TODO Retry if 'result' is None?
|
# TODO Retry if 'result' is None?
|
||||||
return super().invoke(
|
return super().invoke(request, call_receive=call_receive)
|
||||||
request, call_receive=self._recv_thread is None
|
|
||||||
)
|
|
||||||
|
|
||||||
except (PhoneMigrateError, NetworkMigrateError, UserMigrateError) as e:
|
except (PhoneMigrateError, NetworkMigrateError, UserMigrateError) as e:
|
||||||
self._logger.debug('DC error when invoking request, '
|
self._logger.debug('DC error when invoking request, '
|
||||||
|
|
Loading…
Reference in New Issue
Block a user