Comments (6)
the issue and patch seems legit to me, can you submit a PR @peterschutt ?
from uvicorn.
Thanks @euri10 - I'll polish up the patch and submit a PR.
from uvicorn.
I don't think this is a bug. My interpretation from the spec is that once the "lifespan.startup.complete"
is sent, your application is the only task running.
Also, this is the same behavior as the other ASGI servers.
I think what you want is something like this:
import anyio
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette.routing import Route
import uvicorn
async def infinite_task():
while True:
await anyio.sleep(1)
print("I am alive!")
async def health(request: Request):
return JSONResponse({"status": "ok"})
app = Starlette(routes=[Route("/health", health)])
async def main():
async with anyio.create_task_group() as tg:
tg.start_soon(infinite_task)
config = uvicorn.Config(app=app, host="0.0.0.0", port=8002)
server = uvicorn.Server(config=config)
await server.serve()
if __name__ == "__main__":
anyio.run(main, backend_options={"use_uvloop": True})
from uvicorn.
Thanks @Kludex - that pattern will work just fine!
once the "lifespan.startup.complete" is sent, your application is the only task running.
Do you feel there is a disconnect between the spec, and how some frameworks advertise lifespan? For example, from starlette's docs (ref):
Consider using
anyio.create_task_group()
for managing asynchronous tasks.
And from litestar (ref):
This can be useful when dealing with long running tasks
And lastly, from a framework perspective, can we do any better than returning the "lifespan.shutdown.failed" message, in the case where an exception is caught within the lifespan?
from uvicorn.
Do you feel there is a disconnect between the spec, and how some frameworks advertise lifespan? For example, from starlette's docs (ref):
I'm not sure.
And lastly, from a framework perspective, can we do any better than returning the "lifespan.shutdown.failed" message, in the case where an exception is caught within the lifespan?
I don't know.
from uvicorn.
@euri10 can we close this please?
from uvicorn.
Related Issues (20)
- reload doesn't work from programmatic launch (asyncio)
- 16,000 simultaneous request with 16 workers HOT 3
- `--reload-include` doesn't work with hidden files e.g. `--reload-include .env` HOT 1
- ContextVars pollution when uvicorn installed without [standard] extensions HOT 2
- asyncio.exceptions.CancelledError with asyncio HOT 4
- Error: [WinError 10054] An existing connection was forcibly closed by the remote host
- WebSockets and --max-requests does not reload Workers HOT 5
- Add support for Fowarded header (RFC 7239) HOT 3
- uvicorn may respond to requests sent after the client asks for the connection to be closed HOT 11
- Django, uvicorn, gunicorn inside docker HOT 1
- await request.is_disconnected() brings up large ClientDisconnected error in Uvicorn v0.28.0 HOT 7
- WebSocket does not complete coroutine after disconnection HOT 2
- The service process always interrupts abnormally after certain requests
- Child Processes Not Terminating with Uvicorn 0.29.0 HOT 7
- Requirement typo? typing_extensions>=4.0 HOT 1
- Unexcepted behavior while reloading HOT 13
- https://uvicorn.org/ should redirect to https://www.uvicorn.org/ HOT 1
- Unable to get the transport ssl context from the request. This prevents checking the Client provided certificate and matching up the provided CN against allowed users/server.
- `uvicorn.run` `env_file` Not Passed Correctly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uvicorn.