Uvicorn cannot be shutdown programmatically
See original GitHub issueThere is no documented way to shutdown uvicorn in python:
ex:
instance = uvicorn.run("example:app", host="127.0.0.1", port=5000, log_level="info")
instance.shutdown()
How do we shutdown uvicorn?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Uvicorn cannot be shutdown programmatically #1103 - GitHub
Just run await server.serve() in a task and cancel that task when desired, then await server.shutdown() . It's a bit odd that cancelling...
Read more >What is the best way to stop Uvicorn server programmatically?
In Docker, I run uvicorn with bootstrap.sh & command line. In code there is a condition about public key file, if exception occurs,...
Read more >Server Behavior - Uvicorn
Uvicorn handles process shutdown gracefully, ensuring that connections are properly finalized, and all tasks have run to completion. During a shutdown period ...
Read more >tiangolo/fastapi - Gitter
Hi all, Is there a way to trigger FastAPI to shutdown programmatically? Does Uvicorn have a shutdown(), or stop() function?
Read more >Developers - Uvicorn cannot be shutdown programmatically -
There is no documented way to shutdown uvicorn in python: · Overview · Backers (0) · Updates ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
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
Hi,
Not documented indeed, but a multithreaded approach should do…
Very handy to run a live test server locally using a pytest fixture…
I’m following @florimondmanca s approach to run pact tests on the provider side. However when using this i get the following error from uvicorn’s Server.run method:
RuntimeError: There is no current event loop in thread 'Thread-7'.
Any idea on that? Happens with python 3.6.9 as well as 3.7.7.
another edit:
I got it to work using
config = Config("example:app", host="127.0.0.1", port=5000, log_level="info", loop="asyncio")