Use RLocks properly on MtProtoSender (only needed on net IO)

This commit is contained in:
Lonami Exo
2017-09-07 21:32:46 +02:00
parent 16a5ab3070
commit 25bbb20b0c
2 changed files with 19 additions and 38 deletions

View File

@@ -2,7 +2,7 @@ import os
import threading
from datetime import datetime, timedelta
from mimetypes import guess_type
from threading import RLock, Thread
from threading import Thread
from . import TelegramBareClient
from . import helpers as utils
@@ -50,9 +50,6 @@ class TelegramClient(TelegramBareClient):
As opposed to the TelegramBareClient, this one features downloading
media from different data centers, starting a second thread to
handle updates, and some very common functionality.
This should be used when the (slight) overhead of having locks,
threads, and possibly multiple connections is not an issue.
"""
# region Initialization
@@ -118,9 +115,6 @@ class TelegramClient(TelegramBareClient):
timeout=timeout
)
# Safety across multiple threads (for the updates thread)
self._lock = RLock()
# Used on connection - the user may modify these and reconnect
kwargs['app_version'] = kwargs.get('app_version', self.__version__)
for name, value in kwargs.items():
@@ -239,8 +233,6 @@ class TelegramClient(TelegramBareClient):
raise AssertionError('Cannot invoke requests from the ReadThread')
try:
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
@@ -259,9 +251,6 @@ class TelegramClient(TelegramBareClient):
self.reconnect(new_dc=e.new_dc)
return self.invoke(request)
finally:
self._lock.release()
# Let people use client(SomeRequest()) instead client.invoke(...)
__call__ = invoke