uvicorn eats SIGINTs, does not propagate exceptions
See original GitHub issueThe following snippet cannot be killed with a SIGINT (ctrl+c):
import asyncio
from starlette.applications import Starlette
from uvicorn import Config, Server
async def web_ui():
await Server(Config(Starlette())).serve()
async def task():
await asyncio.sleep(100000000000000)
async def main():
await asyncio.gather(web_ui(), task())
if __name__ == "__main__":
asyncio.run(main())
It appears that uvicorn is eating SIGINTs and does not propagate the KeyboardInterrupt and/or Cancelled exceptions. Thanks for having a look.
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:9 (1 by maintainers)
Top Results From Across the Web
uvicorn - Bountysource
I want to be able to configure uvicorn using a python source file similar to how gunicorn does it. uvicorn currently does not...
Read more >How to stop FastAPI app after raising an Exception?
Once an exception is raised, you can use a custom handler, in which you can stop the currently running event loop, using a...
Read more >Exception Handling — Python 3.11.1 documentation
If the error is not handled or carefully propagated, additional calls into the Python/C API may not behave as intended and may fail...
Read more >uvicorn eats SIGINTs, does not propagate exceptions issue
The following snippet cannot be killed with a SIGINT (ctrl+c): import asyncio from starlette.applications import Starlette from uvicorn import Config, ...
Read more >Handling Errors - FastAPI
The client doesn't have enough privileges for that operation. ... HTTPException is a normal Python exception with additional data relevant for APIs.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This has turned out to be a real problem for running an optional
uvicorn
based server inside an existingasyncio
application. SinceServer.serve
finishes gracefully and the original signal handlers are never restored there is no way to ^C the application itself.It looks okay’ish for
Server.serve
to capture signals for graceful shutdown, but it should at least restore the original signal handlers and ideally also reproduce the original behaviour as well. From the looks of it,Server.serve
should raiseKeyboardInterrupt
when done and onlyServer.run
should suppress it.^ courtesy ping for @Kludex , who seems to be the most active maintainer