diff --git a/telethon/tl/tlobject.py b/telethon/tl/tlobject.py index b048158c..57975ec3 100644 --- a/telethon/tl/tlobject.py +++ b/telethon/tl/tlobject.py @@ -5,12 +5,35 @@ from threading import Event class TLObject: def __init__(self): - self.confirm_received = Event() self.rpc_error = None self.result = None # These should be overrode self.content_related = False # Only requests/functions/queries are + + # Internal parameter to tell pickler in which state Event object was + self._event_is_set = False + self._set_event() + + def _set_event(self): + self.confirm_received = Event() + + # Set Event state to 'set' if needed + if self._event_is_set: + self.confirm_received.set() + + def __getstate__(self): + # Save state of the Event object + self._event_is_set = self.confirm_received.is_set() + + # Exclude Event object from dict and return new state + new_dct = dict(self.__dict__) + del new_dct["confirm_received"] + return new_dct + + def __setstate__(self, state): + self.__dict__ = state + self._set_event() # These should not be overrode @staticmethod