question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

uvicorn eats SIGINTs, does not propagate exceptions

See original GitHub issue

The 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:open
  • Created a year ago
  • Reactions:3
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
maxfischer2781commented, Jul 28, 2022

This has turned out to be a real problem for running an optional uvicorn based server inside an existing asyncio application. Since Server.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 raise KeyboardInterrupt when done and only Server.run should suppress it.

1reaction
fastilycommented, Oct 27, 2022

^ courtesy ping for @Kludex , who seems to be the most active maintainer

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found