Add support for ASGI lifespan#46
Merged
anuraaga merged 10 commits intoconnectrpc:mainfrom Nov 19, 2025
Merged
Conversation
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
f55750b to
d9fd56e
Compare
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
i2y
reviewed
Nov 11, 2025
src/connectrpc/_server_async.py
Outdated
|
|
||
|
|
||
| class ConnectASGIApplication(ABC): | ||
| class ConnectASGIApplication(Generic[_SVC]): |
Contributor
There was a problem hiding this comment.
Since this class has abstract methods, maybe it should also inherit from ABC?
Collaborator
Author
There was a problem hiding this comment.
Right, not sure why I thought Generic would imply that - fixed
Collaborator
Author
|
@i2y Can you give this another look? Also @stefanvanburen @spenczar in case this went under the radar. Thanks! |
stefanvanburen
approved these changes
Nov 18, 2025
Contributor
sorry, I just realized.. |
i2y
approved these changes
Nov 18, 2025
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.
I realized we need to support lifespan events to allow asyncio startup / shutdown logic for an app. The simplest way to expose this to users seemed to be accepting either a service or an async generator of a service in the application and resolve either within the lifespan events. We fallback to resolving on first request if the server doesn't support lifespan (this is basically just applying interceptors and shouldn't be a too-large first request penalty), one that notably doesn't is the httpx mock transport we recommend for unit tests.
Let me know any thoughts including the general approach.