我正在使用由 Uvicorn 服务器提供服务的 FastAPI 框架。我的应用程序应该在给定的端点 (/run) 上运行一些耗时的数值计算。为此,我使用来自 fastAPI 的“background_task”(基本上是来自 Starlette 的“background_task”)。
运行应用程序时,经过一段时间的正常行为后,服务器由于某种原因关闭。
应用程序的日志如下所示:
INFO: Started server process [922]
INFO: Waiting for application startup.
DEBUG: None - ASGI [1] Started
DEBUG: None - ASGI [1] Sent {'type': 'lifespan.startup'}
DEBUG: None - ASGI [1] Received {'type': 'lifespan.startup.complete'}
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
DEBUG: ('10.0.2.111', 57396) - Connected
DEBUG: ('10.0.2.111', 57397) - Connected
DEBUG: ('10.0.2.111', 57396) - ASGI [2] Started
DEBUG: ('10.0.2.111', 57396) - ASGI [2] Received {'type': 'http.response.start', …Run Code Online (Sandbox Code Playgroud)