由于后台有 semaphore_tracker 个进程,多进程冻结
Multiprocessing freezing because of semaphore_tracker process in the background
我正在为一个项目使用 Python 多处理,有时进程会冻结,显然它发生的原因是我发现这个进程 运行 ps aux
:
python -c from multiprocessing.semaphore_tracker import main;main(39)
更多信息:
- 如果我终止进程一切正常
- 这个问题并不常见,这意味着可能有几天 运行 一切正常但没有发生
- 我正在使用 PyCharm
- 我正在使用 PyCharm 远程解释器并有时使用 SSH
在服务器中运行此 Python 代码
问题:
- 出现这个过程是怎么回事?
- 为什么它没有自己完成?
- 冻结其他进程的作用是什么?
- 如何避免这种情况?
根据 documentation:
On Unix using the spawn or forkserver start methods will also start a semaphore tracker process which tracks the unlinked named semaphores created by processes of the program.
为什么有人 想要 使用 spawn 启动方法让我不明白。这是 ms-windows 所必需的(非常聪明的)障碍,因为 OS 没有 fork
系统调用。
所以我怀疑 Pycharm 强制使用 forkserver
启动方法,因为它在内部使用多个线程,而标准 UNIX fork
startmethod 不能很好地处理多线程程序。
从 shell 尝试 运行 您的项目。在类 UNIX 操作系统上,应该默认使用 fork
不需要信号量跟踪器进程的启动方法。
我正在为一个项目使用 Python 多处理,有时进程会冻结,显然它发生的原因是我发现这个进程 运行 ps aux
:
python -c from multiprocessing.semaphore_tracker import main;main(39)
更多信息:
- 如果我终止进程一切正常
- 这个问题并不常见,这意味着可能有几天 运行 一切正常但没有发生
- 我正在使用 PyCharm
- 我正在使用 PyCharm 远程解释器并有时使用 SSH 在服务器中运行此 Python 代码
问题:
- 出现这个过程是怎么回事?
- 为什么它没有自己完成?
- 冻结其他进程的作用是什么?
- 如何避免这种情况?
根据 documentation:
On Unix using the spawn or forkserver start methods will also start a semaphore tracker process which tracks the unlinked named semaphores created by processes of the program.
为什么有人 想要 使用 spawn 启动方法让我不明白。这是 ms-windows 所必需的(非常聪明的)障碍,因为 OS 没有 fork
系统调用。
所以我怀疑 Pycharm 强制使用 forkserver
启动方法,因为它在内部使用多个线程,而标准 UNIX fork
startmethod 不能很好地处理多线程程序。
从 shell 尝试 运行 您的项目。在类 UNIX 操作系统上,应该默认使用 fork
不需要信号量跟踪器进程的启动方法。