Unfortunately, starting from uvicorn 0.21.1, when developing with PyCharm, reload cannot terminate the process properly.
The os.kill and signal.CTRL_C_EVENT used in the previous function are based on UNIX system signals, which may not work as expected on Windows. On Windows, the signal mechanism is significantly different from UNIX systems, which might be the reason why it cannot be reloaded normally.
Summary
Unfortunately, starting from uvicorn 0.21.1, when developing with PyCharm, reload cannot terminate the process properly.
The os.kill and signal.CTRL_C_EVENT used in the previous function are based on UNIX system signals, which may not work as expected on Windows. On Windows, the signal mechanism is significantly different from UNIX systems, which might be the reason why it cannot be reloaded normally.
Many versions can't reload properly anymore, I have modified the restart function as: