Skip installation of signal handlers when not in main thread #871
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.
This one has been bogging me for a while, so here's a tentative pull request for it:
Since signals can only be listened to from the main thread, this PR modifies
.install_signal_handlers()
to skip installation of signal handlers when not in the main thread:https://docs.python.org/3/library/signal.html#signals-and-threads
This way, we can also get rid of a bunch of boilerplate overrides of
.install_signal_handlers()
in tests — and many other people will be able to as well (eg we do it in HTTPX, HTTPCore, many of my personal packages, and essentially anywhere one needs to run Uvicorn in a Python thread right now).Surprisingly enough I haven't found an issue open for this yet. :-) But this is somewhat related to #526 (although I don't think it's exactly fixing it).