-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add budget for asyncio Task #126684
Comments
|
Could you please provide more comprehensive example? A working (but maybe incomplete) example would be awesome! |
Our online LLM service currently has two Coroutine Tasks that communicate through an q = asyncio.Queue()
async def task1():
while True:
req = await get_req_from_connection()
do_something(req)
await q.put(req)
async def task2():
req = await q.get()
do_something2(req)Since there are always requests in the connection during load testing,
When a task switches from non-runnable to the runnable state.
Currently, I only have a preliminary idea that hasn't been fully validated, as demonstrated in the following code: diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py
index 5f6fa234872..e4839e51a7d 100644
--- a/Lib/asyncio/futures.py
+++ b/Lib/asyncio/futures.py
@@ -285,6 +285,10 @@ def __await__(self):
if not self.done():
self._asyncio_future_blocking = True
yield self # This tells Task to wait for completion.
+ # Returning True from acquire means that the current task has a budget available
+ # and we have deducted from it.
+ if not current_task_budget.acquire():
+ yield self
if not self.done():
raise RuntimeError("await wasn't used with future")
return self.result() # May raise too. |
|
I see your request. Unfortunately, asyncio works in a different way. Modifying all async functions in asyncio and third-party libraries to decrease a budget doesn't sound like a right way to do things, sorry. P.S. |
|
Thanks |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Feature or enhancement
Proposal:
Should we add a mechanism similar to Per-task operation budget:
The possible modifications are as follows:
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
The text was updated successfully, but these errors were encountered: