mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-03 13:14:31 +03:00
Make creating a new sender cleaner
This commit is contained in:
parent
5da300ca84
commit
0a567fcd7c
|
@ -130,6 +130,13 @@ class Connection:
|
||||||
def close(self):
|
def close(self):
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
|
||||||
|
def clone(self):
|
||||||
|
"""Creates a copy of this Connection"""
|
||||||
|
return Connection(self.ip, self.port,
|
||||||
|
mode=self._mode,
|
||||||
|
proxy=self.conn.proxy,
|
||||||
|
timeout=self.conn.timeout)
|
||||||
|
|
||||||
# region Receive message implementations
|
# region Receive message implementations
|
||||||
|
|
||||||
def recv(self):
|
def recv(self):
|
||||||
|
|
|
@ -54,6 +54,10 @@ class MtProtoSender:
|
||||||
self._need_confirmation.clear()
|
self._need_confirmation.clear()
|
||||||
self._clear_all_pending()
|
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
|
# region Send and receive
|
||||||
|
|
||||||
def send(self, *requests):
|
def send(self, *requests):
|
||||||
|
|
|
@ -388,18 +388,11 @@ class TelegramBareClient:
|
||||||
raise ValueError('You can only invoke requests, not types!')
|
raise ValueError('You can only invoke requests, not types!')
|
||||||
|
|
||||||
# Determine the sender to be used (main or a new connection)
|
# Determine the sender to be used (main or a new connection)
|
||||||
# TODO Polish this so it's nicer
|
|
||||||
on_main_thread = threading.get_ident() == self._main_thread_ident
|
on_main_thread = threading.get_ident() == self._main_thread_ident
|
||||||
if on_main_thread or self._on_read_thread():
|
if on_main_thread or self._on_read_thread():
|
||||||
sender = self._sender
|
sender = self._sender
|
||||||
else:
|
else:
|
||||||
conn = Connection(
|
sender = self._sender.clone()
|
||||||
self.session.server_address, self.session.port,
|
|
||||||
mode=self._sender.connection._mode,
|
|
||||||
proxy=self._sender.connection.conn.proxy,
|
|
||||||
timeout=self._sender.connection.get_timeout()
|
|
||||||
)
|
|
||||||
sender = MtProtoSender(self.session, conn)
|
|
||||||
sender.connect()
|
sender.connect()
|
||||||
|
|
||||||
# We should call receive from this thread if there's no background
|
# We should call receive from this thread if there's no background
|
||||||
|
|
Loading…
Reference in New Issue
Block a user