-
-
Notifications
You must be signed in to change notification settings - Fork 748
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
How do I cancel a streaming response on shutdown? #451
Comments
I didn't try your app, will definitely do as I'm also having issues on shutdown on one of my app and I failed at finding time to make a smaller example than the mess I' currently working on, but this raise interest. Out of curiosity, are you having the |
This is the output I'm getting when I make the http request:
Without making the http request I get:
|
Ok sorry then so it's a little bit different in your case, you loop indefinitely a few lines
above me and never reach lifespan shutdown as the same consequence. I'll try to make a simpler reproducible example of my own issue and post it in a separate thread so that I'm not hijacking yours but I feel like there's something similar going on |
PR welcome to add a The flag will cancel the background tasks, after the number specified. The shutdown event should run after the background tasks are cancelled. |
The code below simulates a server sent event with uvicorn 0.9.
When run, if the HTTP request is not initiated the lifespan startup and shutdown events get called correctly on
^C
.If the HTTP request is made the first
^C
will not stop the responses. The second^C
stops the responses, but the shutdown event is not called.What do I need to do to handle this situation?
The text was updated successfully, but these errors were encountered: