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

Send lifespan.shutdown.failed event on lifespan shutdown error #1205

Closed
wants to merge 4 commits into from

Conversation

JayH5
Copy link
Member

@JayH5 JayH5 commented Jun 19, 2021

Fixes #1138

We supported lifespan.startup.failed but not lifespan.shutdown.failed for some reason. These were added in the Lifespan 2.0 ASGI spec.

Previously, we used single-iteration for-loops to communicate with the lifespan generator. This changes to an explicit try/except StopAsyncIteration, closer to what pytest/AnyIO do when calling test fixtures.

Added additional tests for the incorrect number of yields. Previously we just had an assert on a boolean flag, but now we explicitly raise a RuntimeError (again, similar to pytest which raises this error type in a similar situation).


async def _lifespan_iter(
self, gen: typing.AsyncGenerator, receive: Receive, send: Send
) -> None:
try:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just making lifespan context an asynccontextmanager factory makes all this easier

@JayH5
Copy link
Member Author

JayH5 commented Jul 3, 2021

Superseded by #1227

@JayH5 JayH5 closed this Jul 3, 2021
@JayH5 JayH5 deleted the jh/on-shutdown-failed branch July 3, 2021 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants