@@ -172,6 +172,11 @@ class Client(Methods):
172172 Pass True to hide the password when typing it during the login.
173173 Defaults to False, because ``getpass`` (the library used) is known to be problematic in some
174174 terminal environments.
175+
176+ max_concurrent_transmissions (``bool``, *optional*):
177+ Set the maximum amount of concurrent transmissions (uploads & downloads).
178+ A value that is too high may result in network related issues.
179+ Defaults to 1.
175180 """
176181
177182 APP_VERSION = f"Pyrogram { __version__ } "
@@ -189,6 +194,8 @@ class Client(Methods):
189194 # Interval of seconds in which the updates watchdog will kick in
190195 UPDATES_WATCHDOG_INTERVAL = 5 * 60
191196
197+ MAX_CONCURRENT_TRANSMISSIONS = 1
198+
192199 mimetypes = MimeTypes ()
193200 mimetypes .readfp (StringIO (mime_types ))
194201
@@ -217,7 +224,8 @@ def __init__(
217224 no_updates : bool = None ,
218225 takeout : bool = None ,
219226 sleep_threshold : int = Session .SLEEP_THRESHOLD ,
220- hide_password : bool = False
227+ hide_password : bool = False ,
228+ max_concurrent_transmissions : int = MAX_CONCURRENT_TRANSMISSIONS
221229 ):
222230 super ().__init__ ()
223231
@@ -245,6 +253,7 @@ def __init__(
245253 self .takeout = takeout
246254 self .sleep_threshold = sleep_threshold
247255 self .hide_password = hide_password
256+ self .max_concurrent_transmissions = max_concurrent_transmissions
248257
249258 self .executor = ThreadPoolExecutor (self .workers , thread_name_prefix = "Handler" )
250259
@@ -266,8 +275,8 @@ def __init__(
266275 self .media_sessions = {}
267276 self .media_sessions_lock = asyncio .Lock ()
268277
269- self .save_file_lock = asyncio .Lock ( )
270- self .get_file_lock = asyncio .Lock ( )
278+ self .save_file_semaphore = asyncio .Semaphore ( self . max_concurrent_transmissions )
279+ self .get_file_semaphore = asyncio .Semaphore ( self . max_concurrent_transmissions )
271280
272281 self .is_connected = None
273282 self .is_initialized = None
@@ -798,7 +807,7 @@ async def get_file(
798807 progress : Callable = None ,
799808 progress_args : tuple = ()
800809 ) -> Optional [AsyncGenerator [bytes , None ]]:
801- async with self .get_file_lock :
810+ async with self .get_file_semaphore :
802811 file_type = file_id .file_type
803812
804813 if file_type == FileType .CHAT_PHOTO :
0 commit comments