master.When at last 1 task is submitted to a ProcessPoolExecutor uvicorn fails to reload when a file change has been detected. It detects the file change and the server is shutdown but it doesn't start again. As long as no tasks are submitted uvicorn is able to reload properly.
"""ProcessPoolExecutor Example.
Run
---
uvicorn main:app --reload
Versions
--------
fastapi~=0.63.0
uvicorn[standard]~=0.13.3
"""
from concurrent.futures import ProcessPoolExecutor
from typing import Any, Dict
from fastapi import FastAPI
app = FastAPI(title="Example API")
POOL = ProcessPoolExecutor(max_workers=1)
def task() -> None:
"""."""
print("Executed in process pool")
@app.get("/")
def index() -> Dict[str, Any]:
"""Index."""
POOL.submit(task)
return {"message": "Hello World"}
Uvicorn should reload when file changes are detected.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [9042] using watchgod
INFO: Started server process [9044]
INFO: Waiting for application startup.
INFO: Application startup complete.
WARNING: WatchGodReload detected file change in '['/Users/maartenhuijsmans/main.py']'. Reloading...
INFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
INFO: Finished server process [9044]
INFO: Started server process [9047]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: 127.0.0.1:61607 - "GET / HTTP/1.1" 200 OK
Uvicorn doesn't start
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [9054] using watchgod
INFO: Started server process [9056]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: 127.0.0.1:61615 - "GET / HTTP/1.1" 200 OK
Executed in process pool
WARNING: WatchGodReload detected file change in '['/Users/maartenhuijsmans/main.py']'. Reloading...
INFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
INFO: Finished server process [9056]
uvicorn main:app --reloadincidentally it seems to not happen on #853
@euri10 thanks. I'll be patient and wait for the MR
Most helpful comment
incidentally it seems to not happen on #853