properly close connections when shutting down starlette

This commit is contained in:
Sarah Hoffmann
2023-05-26 11:44:25 +02:00
parent 0843fefad3
commit 75aa3cc9bd

View File

@@ -78,7 +78,11 @@ def get_application(project_dir: Path,
if config.get_bool('CORS_NOACCESSCONTROL'):
middleware.append(Middleware(CORSMiddleware, allow_origins=['*']))
app = Starlette(debug=debug, routes=routes, middleware=middleware)
async def _shutdown() -> None:
await app.state.API.close()
app = Starlette(debug=debug, routes=routes, middleware=middleware,
on_shutdown=[_shutdown])
app.state.API = NominatimAPIAsync(project_dir, environ)