[BUG] "startup" and "shutdown" events not triggered for mounted APIs
See original GitHub issueDescribe the bug
“startup” and “shutdown” events not triggered for mounted APIs
To Reproduce
from fastapi import FastAPI
from fastapi.testclient import TestClient
app = FastAPI()
subapp = FastAPI()
app.mount("/prefix", subapp)
@app.on_event("startup")
async def startup_event_1() -> None:
print("startup for", app)
@app.on_event("shutdown")
async def shutdown_event_1() -> None:
print("shutdown for", app)
@subapp.on_event("startup")
async def startup_event_2() -> None:
print("startup for", subapp)
@subapp.on_event("shutdown")
async def shutdown_event_2() -> None:
print("shutdown for", subapp)
with TestClient(app):
pass
startup/shutdown is triggered for app
but not subapp
Expected behavior
Events are emitted in both cases
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Events: startup - shutdown - FastAPI
These functions can be declared with async def or normal def . Only event handlers for the main application will be executed, not...
Read more >Troubleshoot Start menu errors - Windows Client
In this article. Basic troubleshooting; Check Event logs that record Start Issues: Common errors and mitigation. Applies to: Windows 10.
Read more >How to troubleshoot kernel crashes, hangs, or reboots with ...
The crash dumps are captured from the context of a freshly booted kernel; not from the context of the crashed kernel. Kdump uses...
Read more >View the time / date ranges that your computer was turned on
If you clear your system event log, TurnedOnTimesView will not be able to detect the shutdown/startup times. On systems prior to Windows Vista,...
Read more >Control startup and shutdown order in Compose
However, for startup Compose does not wait until a container is “ready” (whatever that means for your particular application) - only until it's...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
on_startup and on_shutdown only triggered for the the top level app object. That is the expected behaviour in FastAPI. These hooks are implementation of the ASGI spec provided by Starlette and not strictly part of FastAPI. https://asgi.readthedocs.io/en/latest/specs/lifespan.html
Thanks for coming back to close this one! ☕