1. Cause
Due to various reasons, non-standard writing of python code, abnormal IDE configuration, etc. lead to a surge in memory. After checking, it is found that there are hundreds of python.exe running in the background, and even opening the task manager has become a problem (the case occurred in windows, but it still has reference significance under linux).
2. Process
Because the task manager starts slowly and does not refresh, view all tasks in cmd:
tasklist
The output includes a large number of python.exe, and the tasklist command cannot be seen after turning the page. Use taskkill to kill:
taskkill /f /im python.exe
There are a lot of errors:
错误: 无法终止 PID 356 (属于 PID 80088 子进程)的进程。
原因: 没有此任务的实例在运行。
Adding /t to the previous command means to terminate the process and its sub-processes, but never execute it. It may be because of a large number of circular dependencies that the command cannot continue:
taskkill /f /im python.exe /m
3. Solution
According to this situation, in addition to restarting the PC, the most stupid way is to kill the process one by one, then start killing from the smallest pid, 348, 356...
taskkill /f /pid 348 /t
taskkill /f /pid 356 /t
As a result, the two processes were killed, and I was going to check the python.exe of other pids, but all of them disappeared miraculously.
C:\Users\Administrator>taskkill /f /im python.exe
错误: 没有找到进程 "python.exe"。
So far, the problem has been solved and the memory has been successfully reduced.
Then open the task manager and resource manager to check the process, thousands of python.exe are gone.
4. Conclusion
python.exe is just a special case, and other processes can be tried in this case.
under linux
kill -9
I don't know if it can solve all the problems, it may be better than the one under windows
taskkill /m
It is more effective, but if you encounter a problem that kill -9 cannot solve similar parent-child process circular dependencies, you can try to kill -9 from the smallest pid (pid will become larger and larger as the process is created), and it may be effective.