mirror of
https://github.com/SlavikMIPT/tgcloud.git
synced 2025-03-09 15:40:14 +00:00
dynamic threads spawn
This commit is contained in:
parent
4b93bfb74c
commit
2855e60b05
1 changed files with 9 additions and 3 deletions
|
@ -29,7 +29,9 @@ import random
|
||||||
import time
|
import time
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from telethon.network import ConnectionMode
|
from telethon.network import ConnectionMode
|
||||||
from datetime import datetime, timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
|
||||||
class TelegramClientX(TelegramClient):
|
class TelegramClientX(TelegramClient):
|
||||||
def __init__(self, session, api_id, api_hash,
|
def __init__(self, session, api_id, api_hash,
|
||||||
connection_mode=ConnectionMode.TCP_FULL,
|
connection_mode=ConnectionMode.TCP_FULL,
|
||||||
|
@ -91,8 +93,10 @@ class TelegramClientX(TelegramClient):
|
||||||
self.client.disconnect()
|
self.client.disconnect()
|
||||||
print('Thread {0} stopped result {1}'.format(self.name, self.result))
|
print('Thread {0} stopped result {1}'.format(self.name, self.result))
|
||||||
return
|
return
|
||||||
def set_upload_threads_count(self,count: int):
|
|
||||||
|
def set_upload_threads_count(self, count: int):
|
||||||
self._upload_threads_count = int(count)
|
self._upload_threads_count = int(count)
|
||||||
|
|
||||||
def upload_file(self,
|
def upload_file(self,
|
||||||
file,
|
file,
|
||||||
part_size_kb=None,
|
part_size_kb=None,
|
||||||
|
@ -198,6 +202,8 @@ class TelegramClientX(TelegramClient):
|
||||||
file_size, part_count, part_size)
|
file_size, part_count, part_size)
|
||||||
|
|
||||||
with open(file, 'rb') if isinstance(file, str) else BytesIO(file) as stream:
|
with open(file, 'rb') if isinstance(file, str) else BytesIO(file) as stream:
|
||||||
|
threads_count = 2 + int((self._upload_threads_count - 2) * part_count * 0.000325520)
|
||||||
|
if threads_count > self._upload_threads_count:
|
||||||
threads_count = self._upload_threads_count
|
threads_count = self._upload_threads_count
|
||||||
if part_count < threads_count:
|
if part_count < threads_count:
|
||||||
threads_count = part_count
|
threads_count = part_count
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue