Compare commits
2 Commits
mtpager
...
fix-thread
Author | SHA1 | Date | |
---|---|---|---|
|
b59752e848 | ||
|
30d3658e19 |
@ -229,7 +229,9 @@ class Client(Methods, Scaffold):
|
||||
self.sleep_threshold = sleep_threshold
|
||||
self.hide_password = hide_password
|
||||
|
||||
self.executor = ThreadPoolExecutor(self.workers, thread_name_prefix="Handler")
|
||||
self.handler_executor = ThreadPoolExecutor(32, thread_name_prefix="Handler")
|
||||
self.filter_executor = ThreadPoolExecutor(32, thread_name_prefix="Filter")
|
||||
self.progress_executor = ThreadPoolExecutor(32, thread_name_prefix="Progress")
|
||||
|
||||
if isinstance(session_name, str):
|
||||
if session_name == ":memory:" or len(session_name) >= MemoryStorage.SESSION_STRING_SIZE:
|
||||
@ -934,7 +936,7 @@ class Client(Methods, Scaffold):
|
||||
if inspect.iscoroutinefunction(progress):
|
||||
await func()
|
||||
else:
|
||||
await self.loop.run_in_executor(self.executor, func)
|
||||
await self.loop.run_in_executor(self.progress_executor, func)
|
||||
|
||||
r = await session.send(
|
||||
raw.functions.upload.GetFile(
|
||||
@ -1024,7 +1026,7 @@ class Client(Methods, Scaffold):
|
||||
if inspect.iscoroutinefunction(progress):
|
||||
await func()
|
||||
else:
|
||||
await self.loop.run_in_executor(self.executor, func)
|
||||
await self.loop.run_in_executor(self.progress_executor, func)
|
||||
|
||||
if len(chunk) < limit:
|
||||
break
|
||||
|
@ -217,7 +217,7 @@ class Dispatcher:
|
||||
await handler.callback(self.client, *args)
|
||||
else:
|
||||
await self.loop.run_in_executor(
|
||||
self.client.executor,
|
||||
self.client.handler_executor,
|
||||
handler.callback,
|
||||
self.client,
|
||||
*args
|
||||
|
@ -47,7 +47,7 @@ class InvertFilter(Filter):
|
||||
x = await self.base(client, update)
|
||||
else:
|
||||
x = await client.loop.run_in_executor(
|
||||
client.executor,
|
||||
client.filter_executor,
|
||||
self.base,
|
||||
client, update
|
||||
)
|
||||
@ -65,7 +65,7 @@ class AndFilter(Filter):
|
||||
x = await self.base(client, update)
|
||||
else:
|
||||
x = await client.loop.run_in_executor(
|
||||
client.executor,
|
||||
client.filter_executor,
|
||||
self.base,
|
||||
client, update
|
||||
)
|
||||
@ -78,7 +78,7 @@ class AndFilter(Filter):
|
||||
y = await self.other(client, update)
|
||||
else:
|
||||
y = await client.loop.run_in_executor(
|
||||
client.executor,
|
||||
client.filter_executor,
|
||||
self.other,
|
||||
client, update
|
||||
)
|
||||
@ -96,7 +96,7 @@ class OrFilter(Filter):
|
||||
x = await self.base(client, update)
|
||||
else:
|
||||
x = await client.loop.run_in_executor(
|
||||
client.executor,
|
||||
client.filter_executor,
|
||||
self.base,
|
||||
client, update
|
||||
)
|
||||
@ -109,7 +109,7 @@ class OrFilter(Filter):
|
||||
y = await self.other(client, update)
|
||||
else:
|
||||
y = await client.loop.run_in_executor(
|
||||
client.executor,
|
||||
client.filter_executor,
|
||||
self.other,
|
||||
client, update
|
||||
)
|
||||
|
@ -35,7 +35,7 @@ class Handler:
|
||||
return await self.filters(client, update)
|
||||
else:
|
||||
return await client.loop.run_in_executor(
|
||||
client.executor,
|
||||
client.handler_executor,
|
||||
self.filters,
|
||||
client, update
|
||||
)
|
||||
|
@ -193,7 +193,7 @@ class SaveFile(Scaffold):
|
||||
if inspect.iscoroutinefunction(progress):
|
||||
await func()
|
||||
else:
|
||||
await self.loop.run_in_executor(self.executor, func)
|
||||
await self.loop.run_in_executor(self.progress_executor, func)
|
||||
except StopTransmission:
|
||||
raise
|
||||
except Exception as e:
|
||||
|
@ -83,7 +83,9 @@ class Scaffold:
|
||||
self.takeout = None
|
||||
self.sleep_threshold = None
|
||||
|
||||
self.executor = None
|
||||
self.handler_executor = None
|
||||
self.filter_executor = None
|
||||
self.progress_executor = None
|
||||
|
||||
self.storage = None
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user