From 64813d5464b6bb2aeaa2c605b56def901e8b736a Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Sat, 17 Oct 2026 16:30:37 +0300 Subject: [PATCH] docs: say which shutdown hooks run after the root container closes --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 78c9993..09e1825 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,16 @@ async def main() -> None: APP-scoped finalizers run once, when the `async with` block exits. +### Shutdown order + +`setup_di` appends the root container's close to `app.on_cleanup`. These hooks run before the close and can still resolve from the container: + +- `on_shutdown` handlers +- `cleanup_ctx` teardown +- `on_cleanup` handlers added before `setup_di` + +`on_cleanup` handlers added after `setup_di` run after the close and get `ContainerClosedError`. Add them before `setup_di`. If you can't, pass `manage_lifespan=False` and close the container yourself after `runner.cleanup()`, as in the example above. + ## API | Symbol | Description |