Skip to content
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

fastapi-streaming-example - perhaps creating a new thread can be avoided & instead use create_task #93

Open
ksachdeva opened this issue Nov 20, 2024 · 1 comment
Labels
bug Something isn't working triage

Comments

@ksachdeva
Copy link

Expected Behaviour

minimize or eliminate thread creation if the entire stack is async

Current Behaviour

Thread(target=lambda: asyncio.run(start_generation(query, user_id, session_id, streamer_queue))).start()

Above line will spawn a new thread for every request.

Code snippet

https://github.com/awslabs/multi-agent-orchestrator/blob/da9563fe9e87343fcda8abe6303b1e1d4f36c943/examples/fast-api-streaming/main.py#L119

Possible Solution

What would be an issue if you do the following -

asyncio.create_task(start_generation(query, user_id, session_id, streamer_queue))

instead of spawning a new thread

Steps to Reproduce

See -

Thread(target=lambda: asyncio.run(start_generation(query, user_id, session_id, streamer_queue))).start()

@ksachdeva ksachdeva added the bug Something isn't working label Nov 20, 2024
@brnaba-aws
Copy link
Contributor

Hi @ksachdeva
Thanks for you contribution.
This is a code example, just to show dev how they might use it. People are free to take the code and modify it the way they want.

Thanks,
Anthony

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

2 participants