-
-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uvicorn with reload hangs when using a ProcessPoolExecutor #936
Comments
incidentally it seems to not happen on #853 |
@euri10 thanks. I'll be patient and wait for the MR |
Similar issue, probably same root cause: when using a lock to mutate shared state, if the lock is acquired when a reload starts, the new process can never be
|
definitely stalled yes |
This is not a bug. It works as intended. On the That said, we have two options:
On from concurrent.futures import ProcessPoolExecutor
from typing import Any, Dict
from fastapi import FastAPI
app = FastAPI(title="Example API")
POOL = None
@app.on_event("startup")
def startup():
global POOL
POOL = ProcessPoolExecutor(max_workers=1)
@app.on_event("shutdown")
def shutdown():
global POOL
POOL.shutdown()
def task() -> None:
"""."""
print("Executed in process pool")
@app.get("/")
def index() -> Dict[str, Any]:
"""Index."""
POOL.submit(task)
return {"message": "Hello World"} Given that the snippet above already satisfies this issue, and that I've provided explanation about what's happening, I'll be closing this issue. If there's a good argument, and a proposal to implement |
Checklist
master
.Describe the bug
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.To reproduce
Expected behavior
Uvicorn should reload when file changes are detected.
Actual behavior
Uvicorn doesn't start
Debugging material
Environment
uvicorn main:app --reload
Additional context
The text was updated successfully, but these errors were encountered: