llama-stack-mirror/llama_stack/distribution/server
Ashwin Bharambe 9e3ae50306
feat(server): construct the stack in a persistent event loop (#2818)
When we call `construct_stack()`, providers are instantiated and
`initialize()` is called. This call can end up doing _anything_ at all
-- specifically, providers are free to create long running background
tasks as part of this. If we wrapped this within a `asyncio.run()` as in
the current code, these tasks get canceled when the stack construction
finishes. This is not correct. The PR addresses the issue by creating a
persistent event loop which is used for both the stack as well as for
running the uvicorn server. In other words, the lifetime of the
providers (and downstream async code) is now the same as the lifetime of
the uvicorn server.

## Test Plan

This should not affect any current code since we don't have background
tasks created right now. However,
https://github.com/meta-llama/llama-stack/pull/2805 will start using
this functionality.
2025-07-18 10:29:19 -07:00
..
__init__.py API Updates (#73) 2024-09-17 19:51:35 -07:00
auth.py feat(auth): support github tokens (#2509) 2025-07-08 11:02:36 -07:00
auth_providers.py feat(auth): support github tokens (#2509) 2025-07-08 11:02:36 -07:00
quota.py feat: drop python 3.10 support (#2469) 2025-06-19 12:07:14 +05:30
routes.py chore: use starlette built-in Route class (#2267) 2025-05-28 09:53:33 -07:00
server.py feat(server): construct the stack in a persistent event loop (#2818) 2025-07-18 10:29:19 -07:00