-
-
Notifications
You must be signed in to change notification settings - Fork 954
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
Support generator function to manage startup/shutdown. #799
Conversation
Starlette(..., lifespan=...)
Starlette(..., lifespan=...)
Using this approach, I have two questions:
|
|
Having looked into it, you can't loop though a sync and an async iterator with the same kind of loop, so it would mean duplicating the iteration part, which would be unneccessarily noisy. It probably wouldn't be worth it anyway, so nervermind that.
That's good if it turns out that way, lifespan has a number of caveats that make it unreliable (#649) or impractical (what this PR attempts to fix) to use right now. That's probably out of scope for this PR, though. |
Works for me, just be sure to properly document that lifespan and startup/shutdown are mutually exclusive (at least, in this implementation). |
Alrighty, for completeness I've added support for the function to be either a generator or an async generator. |
When can we expect a release with this feature? |
An alternate implementation of #785
lifespan_context=...
argument toStarlette
andRouter
.app
argument to the lifespan context function.End result API would be allowing the application to take a single
async
generator function, that can encapsulate any required startup/shutdown logic.Taking the example in #785, you'd end up with this kind of pattern...