Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR quiets the
KeyboardInterrupt
when quitting a programatic run ofuvicorn
.The default traceback is much shorter now. It shows that it originates in
uvicorn
and notes that it quits uvicorn to avoid confusing it with a regular error.New traceback
Old traceback
uvicorn.run
now has a flagsuppress_ki
that completely silences theKeyboardInterrupt
. This allows programmatic usage to almost restore the pre-Cooperative signal handling #1600 behaviour - the noisy exception is gone (as before), but triggering CTRL+C again still allows to shut down the program (as is usual for Python).Open design decisions
Should
suppress_ki
default toTrue
? It's no problem for the CLI to set it explicitly toFalse
andasync
code (which motivated #1600) does not go through this function at all.Is
suppress_ki
a suitable name?ki
is commonly used as an abbreviation ofKeyboardInterrupt
(see e.g.trio
) but usually only needed in very technical situations.Checklist