-
-
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
Support --before-graceful-exit
#2242
base: master
Are you sure you want to change the base?
Conversation
This PR adds a quite useful feature. One of the applications where I am using uvicorn has clients that use long polling to get notifications from the server using plain HTTP 1.1 and every time the application is stopped, it logs errors like this one:
The hook added by this PR would make it possible to avoid such errors without any tricks like patching uvicorn's internal methods. |
Could you use https://www.uvicorn.org/deployment/#running-programmatically? never mind I have had misunderstood the problem |
@Kludex Do you have any other opinions? I noticed that you added a "hold" tag. |
Yes, we didn't discuss this properly. Give me a chance to review the previous issues, and discussions, please. |
If there is no problem, can this PR be merged? It solves a problem that has been around for years. |
I would like to take a look first. |
if callable(self.config.before_graceful_exit_hook): | ||
f = self.config.before_graceful_exit_hook() | ||
if inspect.isawaitable(f): | ||
await f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to place this code prior to the point where new connections are no longer accepted (#Stop accepting new connections)?
This could help in resolving the matter we have mentioned in #2257. Additionally, since the topic at hand is related to "before graceful exit," it would be good to execute the code beforehand, before the acceptance of any further connections is stopped.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no objection to this, for me these two positions are the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @Kludex |
Summary
About #1936
The PR will solved https://stackoverflow.com/questions/58133694/graceful-shutdown-of-uvicorn-starlette-app-with-websockets
Checklist