feat(server): construct the stack in a persistent event loop#2818
Merged
ashwinb merged 1 commit intollamastack:mainfrom Jul 18, 2025
Merged
feat(server): construct the stack in a persistent event loop#2818ashwinb merged 1 commit intollamastack:mainfrom
ashwinb merged 1 commit intollamastack:mainfrom
Conversation
cdoern
reviewed
Jul 18, 2025
Collaborator
cdoern
left a comment
There was a problem hiding this comment.
this makes sense to me, one question
cdoern
approved these changes
Jul 18, 2025
reluctantfuturist
approved these changes
Jul 18, 2025
leseb
added a commit
to leseb/llama-stack
that referenced
this pull request
Jul 21, 2025
After llamastack#2818, SIGINT will print a stack trace. This is because uvicorn re-raises SIGINT and it gets converted by Python internal signal handler (default handles SIGINT) to KeyboardInterrupt exception. We know simply catch the exception to get a clean exit, this is not changing the behavior on SIGINT. Signed-off-by: Sébastien Han <seb@redhat.com>
ashwinb
pushed a commit
that referenced
this pull request
Jul 21, 2025
# What does this PR do? After #2818, SIGINT will print a stack trace. This is because uvicorn re-raises SIGINT and it gets converted by Python internal signal handler (default handles SIGINT) to KeyboardInterrupt exception. We know simply catch the exception to get a clean exit, this is not changing the behavior on SIGINT. ## Test Plan Run the server, hit Ctrl+C or `kill -2 <server pid>` and expect a clean exit with no stack trace. Signed-off-by: Sébastien Han <seb@redhat.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When we call
construct_stack(), providers are instantiated andinitialize()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 aasyncio.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, #2805 will start using this functionality.