I currently have a fastapi deployed with uvicorn that starts a thread on initialisation (among other things) using threading
.
This thread is infinite (it's a routine that updates every x seconds).
Before I updated to python 3.10, everything was working fine, everytime I changed the code, the server would detect change and reload, killing and creating a new thread at init.
But now, when I modify my code, the server detects change and try to reload but the created thread isn't killed (print still continue to flow in the console) refraining the server to fully reload.
my print from my thread
WARNING: StatReload detected changes in 'app\api.py'. Reloading...
INFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
INFO: Finished server process [3736]
my print from my thread
my print from my thread
...
This works the same way if I ctrl+C in the console. The thread stays alive
My solution for the moment is to kill PID
everytime I want to refresh but that's a bit annoying.
I tried to get back to python 3.7.9 but the problem remains.
I also tried to implement atexit
and manually kill the process but it didn't work.
Any lead on how to properly handle this ?
Fixed by downgrading uvicorn to an older version (0.19.0 works).