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

Document the lifespan event handler parameter #1110

Merged
merged 4 commits into from Jul 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/events.md
Expand Up @@ -37,6 +37,25 @@ registered startup handlers have completed.
The shutdown handlers will run once all connections have been closed, and
any in-process background tasks have completed.

A single lifespan asyncronous generator handler can be used instead of
emilmelnikov marked this conversation as resolved.
Show resolved Hide resolved
separate startup and shutdown handlers:

```python
from starlette.applications import Starlette


async def lifespan(app):
emilmelnikov marked this conversation as resolved.
Show resolved Hide resolved
# Execute startup tasks.
yield
# Execute shutdown tasks.

routes = [
...
]

app = Starlette(routes=routes, lifespan=lifespan)
```

## Running event handlers in tests

You might want to explicitly call into your event handlers in any test setup
Expand Down