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

Support startup, shutdown, and timer events. #58

Closed
tomchristie opened this issue Oct 16, 2018 · 2 comments
Closed

Support startup, shutdown, and timer events. #58

tomchristie opened this issue Oct 16, 2018 · 2 comments
Labels
enhancement New feature or request

Comments

@tomchristie
Copy link
Contributor

ASGI includes a lifespan messaging channel, which provides startup and shutdown events.
This also means there's a managed context within which we can hook timer events.

Interfaces for this might look something like...

@app.on_event('startup')
async def startup():
    ...
@app.on_event('tick', seconds=10)
async def do_stuff():
    ...
@app.on_event('shutdown')
async def startup():
    ...

These would be a nice easy win that ASGI gives us which WSGI isn't able to.

Starlette currently supports startup and shutdown events, so that's a good first place to look for implementation... https://www.starlette.io/events/

@kennethreitz kennethreitz added the enhancement New feature or request label Oct 17, 2018
@kennethreitz
Copy link
Owner

I'm not convinced this is a good idea, at this time.

@pbsds
Copy link
Contributor

pbsds commented Oct 25, 2018

Please don't close this yet. The startup one is kinda essential to be honest if you want to perform async setup, like creating a dbpool:

This is due to the event loop not being created before after you've run api.run(), which then blocks.
You could pass your own loop instance as an option into api.run() which would then be passed into uvicorn to use, but it isn't pretty nor pythonic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants