torch 分布式程序产生僵尸进程
聊天记录:
A torch 的分布式程序在一些异常结束的情况下会留下一些僵尸进程 我之前经常是这样 你 kill 掉主进程子进程不会被回收
B 为什么没有会回收?因为父进程没死且没有被回收,难道父进程不是 torch 的主进程,而是整个容器里面的一个活跃进程? 不在容器里使用是否不会出现这种情况? 如果父进程死了,应该由 init 回收 是否是因为容器的起始进程不是 init
A 不知道
B 是在容器中吗
A 不是
关联:
论坛帖子 PyTorch doesn’t free GPU’s memory of it gets aborted due to out-of-memory error - PyTorch Forums 有 PyTorch 开发者回答是 Python 的 multiprocessing 模块有 bug,可能会导致僵尸进程。
@rabst so, I remember this issue. When investigating, we found that there’s actually a bug in python multiprocessing that might keep the child process hanging around, as zombie processes. It is not even visible to
nvidia-smi
.The solution is
killall python
, or tops -elf | grep python
and find them andkill -9 [pid]
to them.
根据网上的说法:Python 是使用子进程而不是线程来实现 multiprocessing
模块的,因为 CPython 有 GIL 的限制,这使得不同的线程不能同时解释 Python 字节码。
multiprocessing
和subprocess
模块的比较:前者还是使用 Python 解释器来执行 Python 代码,进程通信的过程是透明化的;后者则是启动其他命令或程序。