You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to limit the concurrent execution of tasks in the broker, so I set sync_tasks_pool_size=1 and max_async_tasks=1, but it didn't work as expected, and the tasks are still running all at once. I noticed that the Semaphore defined by these two options in the Receiver is not applied in callback and run_task. Is my usage incorrect, or is there a way to limit the number of concurrent tasks? Below is my code. I really like the design of TaskIQ, and I look forward to your response.
Code
import asyncio
from taskiq import InMemoryBroker
from taskiq.kicker import AsyncKicker
from taskiq_example.middleware import TestMiddleware
Env
python: 3.12.3
os: window 10
taskiq: 0.11.10
Q
I want to limit the concurrent execution of tasks in the broker, so I set sync_tasks_pool_size=1 and max_async_tasks=1, but it didn't work as expected, and the tasks are still running all at once. I noticed that the Semaphore defined by these two options in the Receiver is not applied in callback and run_task. Is my usage incorrect, or is there a way to limit the number of concurrent tasks? Below is my code. I really like the design of TaskIQ, and I look forward to your response.
Code
import asyncio
from taskiq import InMemoryBroker
from taskiq.kicker import AsyncKicker
from taskiq_example.middleware import TestMiddleware
broker = InMemoryBroker(
sync_tasks_pool_size=1,
max_async_tasks=1
)
broker.add_middlewares(TestMiddleware())
async def best_task_ever(value: int) -> bool:
"""Solve all problems in the world."""
print("execute best_task_ever", value)
await asyncio.sleep(5)
return True
async def main():
await broker.register_task(best_task_ever).kiq(1)
await broker.register_task(best_task_ever).kiq(2)
await broker.register_task(best_task_ever).kiq(3)
await broker.register_task(best_task_ever).kiq(4)
if name == "main":
asyncio.run(main())
Result
It executes 5 tasks concurrently, taking about 5-6 seconds.
I need to control it so that the tasks are executed one by one.
The text was updated successfully, but these errors were encountered: