Compare commits

...

2 Commits

Author SHA1 Message Date
Dan
b59752e848 Test higher amount of threads
#663
2021-04-10 12:56:00 +02:00
Dan
30d3658e19 This should fix the deadlock happening on callbacks using the same pool
Related to #663
2021-04-10 12:34:04 +02:00
6 changed files with 16 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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
)

View File

@ -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
)

View File

@ -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:

View File

@ -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