mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-09 05:19:41 +00:00
Make confirm_received a flag, avoid race conditions, fix bg RPCError
There was a race condition between TelegramBareClient.invoke receiving part and MtProtoSender._handle_rpc_result actually reading the result after setting request.confirmed = True. The .confirmed is now a threading.Event to avoid the sleep(0.1). RPC errors have been moved inside the request so they're not raised on a background thread anymore.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime, timedelta
|
||||
from threading import Event
|
||||
|
||||
|
||||
class TLObject:
|
||||
@@ -10,7 +11,8 @@ class TLObject:
|
||||
|
||||
self.dirty = False
|
||||
self.send_time = None
|
||||
self.confirm_received = False
|
||||
self.confirm_received = Event()
|
||||
self.rpc_error = None
|
||||
|
||||
# These should be overrode
|
||||
self.constructor_id = 0
|
||||
@@ -23,11 +25,11 @@ class TLObject:
|
||||
self.sent = True
|
||||
|
||||
def on_confirm(self):
|
||||
self.confirm_received = True
|
||||
self.confirm_received.set()
|
||||
|
||||
def need_resend(self):
|
||||
return self.dirty or (
|
||||
self.content_related and not self.confirm_received and
|
||||
self.content_related and not self.confirm_received.is_set() and
|
||||
datetime.now() - self.send_time > timedelta(seconds=3))
|
||||
|
||||
@staticmethod
|
||||
|
Reference in New Issue
Block a user