Remove temporary connections and use a lock again

These seem to be the reason for missing some updates (#237)
This commit is contained in:
Lonami Exo
2018-01-06 23:43:40 +01:00
parent 7745b8e7ee
commit d81dd055e6
2 changed files with 31 additions and 68 deletions

View File

@@ -5,6 +5,7 @@ encrypting every packet, and relies on a valid AuthKey in the used Session.
import gzip
import logging
import struct
from threading import Lock
from .. import helpers as utils
from ..crypto import AES
@@ -53,6 +54,9 @@ class MtProtoSender:
# Requests (as msg_id: Message) sent waiting to be received
self._pending_receive = {}
# Multithreading
self._send_lock = Lock()
def connect(self):
"""Connects to the server."""
self.connection.connect(self.session.server_address, self.session.port)
@@ -71,10 +75,6 @@ class MtProtoSender:
self._need_confirmation.clear()
self._clear_all_pending()
def clone(self):
"""Creates a copy of this MtProtoSender as a new connection."""
return MtProtoSender(self.session, self.connection.clone())
# region Send and receive
def send(self, *requests):
@@ -156,7 +156,8 @@ class MtProtoSender:
:param message: the TLMessage to be sent.
"""
self.connection.send(utils.pack_message(self.session, message))
with self._send_lock:
self.connection.send(utils.pack_message(self.session, message))
def _decode_msg(self, body):
"""