This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: multiprocessing.Pool hangs forever on segfault
类型: behavior Stage: resolved
Components: Versions: Python 3.4
process
状态: closed Resolution: duplicate
Dependencies: 后续: multiprocessing.Pool shouldn't hang forever if a worker process dies unexpectedly
View: 22393
分配给: 抄送列表: Jonas Obrist, brianboonstra, jnoller, sbt
优先级: normal 关键字: patch

Created on 2015-08-24 17:05 by Jonas Obrist, last changed 2022-04-11 14:58 by admin. This issue is now closed.

文件
文件名 上传时间 Description 编辑
pool_segfault.py Jonas Obrist, 2015-08-24 18:00 Program showing how a segfaulting Pool.apply will hang forever
process_segfault.py Jonas Obrist, 2015-08-24 18:00 Program showing that Process will run as expected if target segfaults
patch.diff Jonas Obrist, 2015-08-25 18:22 patch that adds a warning if a worker exits prematurely review
Messages (4)
msg249068 - (view) Author: Jonas Obrist (Jonas Obrist) * 日期: 2015-08-24 17:05
When using multiprocessing.Pool, if the function run in the pool segfaults, the program will simply hang forever. However when using multiprocessing.Process directly, it runs fine, setting the exitcode to -11 as expected.

I would expect the Pool to behave similar to Process, or at the very least an exception to be raised instead of just silently hanging forever.

I was able to reproduce this issue both on Linux (Ubuntu 15.04) and Mac OS X.
msg249077 - (view) Author: Jonas Obrist (Jonas Obrist) * 日期: 2015-08-24 21:56
So the reason this is happening is very simple:

When using Pool.apply, the task (function) is sent to the task queue, which is consumed by the worker. At this point the task is "in progress". However, the worker dies without being able to finish the task or in any other way tell the Pool that it can't finish the task. The actual process is then ended by the Pool but the task is still in limbo, so any attempt at getting a result will hang forever.

I'm not sure there's a straight forward way to solve this (the ways I can think of from the top of my head involve adding quite a bit of overhead to the Pool so it keeps track of which process/worker is handling which task at a given time, so if it exits prematurely this task can be finished), but at the very least this case should be documented I think.
msg249147 - (view) Author: Jonas Obrist (Jonas Obrist) * 日期: 2015-08-25 18:22
I've added a patch that would simply warn the user if a worker exits prematurely.
msg250474 - (view) Author: Brian Boonstra (brianboonstra) 日期: 2015-09-11 13:58
See also issue 22393
历史
日期 用户 动作 参数
2022-04-11 14:58:20admin修改github: 69115
2015-09-16 17:01:10berker.peksag修改后续: multiprocessing.Pool shouldn't hang forever if a worker process dies unexpectedly
stage: resolved
2015-09-16 11:47:34Jonas Obrist修改状态: open -> closed
resolution: duplicate
2015-09-11 13:58:47brianboonstra修改抄送: + brianboonstra
消息: + msg250474
2015-08-25 18:22:37Jonas Obrist修改文件: + patch.diff
keywords: + patch
消息: + msg249147
2015-08-24 21:56:57Jonas Obrist修改消息: + msg249077
2015-08-24 18:00:55Jonas Obrist修改文件: + process_segfault.py
2015-08-24 18:00:30Jonas Obrist修改文件: + pool_segfault.py
2015-08-24 18:00:09Jonas Obrist修改文件: - process_segfault.py
2015-08-24 18:00:06Jonas Obrist修改文件: - pool_segfault.py
2015-08-24 18:00:01Jonas Obrist修改文件: - setup.py
2015-08-24 17:59:57Jonas Obrist修改文件: - segfault.c
2015-08-24 17:06:39Jonas Obrist修改文件: + process_segfault.py
2015-08-24 17:06:22Jonas Obrist修改文件: + setup.py
2015-08-24 17:05:56Jonas Obrist修改文件: + segfault.c
2015-08-24 17:05:17Jonas Obrist创建