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.
Created on 2010年04月03日 03:37 by vlasovskikh, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| test_map_keyboard_interrput.py | vlasovskikh, 2010年04月06日 18:21 | Unit test | ||
| fix-sigint.diff | vlasovskikh, 2010年04月06日 18:32 | First patch fixing the problem | ||
| Messages (15) | |||
|---|---|---|---|
| msg102219 - (view) | Author: Andrey Vlasovskikh (vlasovskikh) * | Date: 2010年04月03日 03:37 | |
multiprocessing.Pool methods map, imap, etc. are said to be able to normally handle exceptions. But it seems that it is true only for synchronous exceptions inside their first func arguments. When (typically during a long-running parallel map) a user hits ^C, an asynchronous KeyboardInterrupt isn't handled properly and leads to the interpreter hangup. More precisely, children processes become <defunct> (on Linux), so the only way to terminate the whole program is to issue the KILL signal. As stopping a program with ^C while running potentially long parallel computations is probably quite a common scenario, the interpreter should not hang up in such a case. I'm using Python 2.6.5 (r265:79063, Mar 23 2010, 04:44:21) [GCC 4.4.3] on linux2. I've also tried to use the current multiprocessing.pool module from the current (2.7) trunk with my 2.6.5 installation, but the bug persists. |
|||
| msg102220 - (view) | Author: Brian Curtin (brian.curtin) * (Python committer) | Date: 2010年04月03日 03:39 | |
Do you have a test case which can reproduce the issue? |
|||
| msg102221 - (view) | Author: Andrey Vlasovskikh (vlasovskikh) * | Date: 2010年04月03日 03:45 | |
Yes, here is my test case. |
|||
| msg102222 - (view) | Author: Brian Curtin (brian.curtin) * (Python committer) | Date: 2010年04月03日 03:54 | |
You might want to take a look here: http://jessenoller.com/2009/01/08/multiprocessingpool-and-keyboardinterrupt/ |
|||
| msg102223 - (view) | Author: Andrey Vlasovskikh (vlasovskikh) * | Date: 2010年04月03日 04:07 | |
Yes, I've come up with the same solution by myself, but it cannot cover all the cases of the bug. It works only for cases when ^C is hit during a call to the users' function: http://stackoverflow.com/questions/1408356/keyboard-interrupts-with-pythons-multiprocessing-pool/2561809#2561809 If the user is "lucky", he may hit ^C during getting or putting data into the queues in multiprocessing.pool.worker. To reproduce such a case, you may insert `sleep(10)` before `task = get()` or `put((job, i, result))`, for example. I've encountered such cases just by running test examples several times. |
|||
| msg102479 - (view) | Author: Andrey Vlasovskikh (vlasovskikh) * | Date: 2010年04月06日 18:21 | |
Despite of several workarounds available on the Web, the problem persists. Almost any exception that is rised in `worker` function while putting or getting tasks from queues result in Pool hang up. Currently, `worker` is only aware of Exception descendants rised inside of the map function parameter. I've written a unit test that checks if KeyboardInterrupts are handled normally. The source code may be included in `Lib/test/test_multiprocessing.py`. |
|||
| msg102481 - (view) | Author: Andrey Vlasovskikh (vlasovskikh) * | Date: 2010年04月06日 18:32 | |
Here is a patch that fixes this problem. Basically, it catches all the BaseExceptions that could happen during: a) getting a task from the `inqueue`, b) calling a user function, c) putting a task into the `outqueue`. The exception handler puts the exception to the `outqueue`. It can be cleanly applied on top of revision 78790. |
|||
| msg114817 - (view) | Author: Albert Strasheim (Albert.Strasheim) | Date: 2010年08月24日 20:26 | |
Any chance of getting this patch applied? Thanks. |
|||
| msg114821 - (view) | Author: Ask Solem (asksol) (Python committer) | Date: 2010年08月24日 20:40 | |
This is related to our discussions at #9205 as well (http://bugs.python.org/issue9205), as the final patch there will also fix this issue. |
|||
| msg114888 - (view) | Author: Ask Solem (asksol) (Python committer) | Date: 2010年08月25日 08:43 | |
On closer look your patch is also ignoring SystemExit. I think it's beneficial to honor SystemExit, so a user could use this as a means to replace the current process with a new one. If we keep that behavior, the real problem here is that the result handler hangs if the process that reserved a job is gone, which is going to be handled by #9205. Should we mark it as a duplicate? |
|||
| msg114900 - (view) | Author: Jesse Noller (jnoller) * (Python committer) | Date: 2010年08月25日 13:30 | |
> If we keep that behavior, the real problem here is that the > result handler hangs if the process that reserved a job is gone, which is going to be handled > by #9205. Should we mark it as a duplicate? I would tend to agree with your assessment; we're better served just gracefully handling everything per 9205 |
|||
| msg114976 - (view) | Author: Andrey Vlasovskikh (vlasovskikh) * | Date: 2010年08月26日 13:48 | |
> On closer look your patch is also ignoring SystemExit. I think it's beneficial to honor SystemExit, so a user could use this as a means to replace the current process with a new one. Yes, SystemExit should cancel all the tasks that are currently in the queue. I guess my patch doesn't handle this properly. > If we keep that behavior, the real problem here is that the result handler hangs if the process that reserved a job is gone, which is going to be handled by #9205. Should we mark it as a duplicate? Yes, I think that #9205 covers this issue, so #8296 may be marked as a duplicate. |
|||
| msg143077 - (view) | Author: Vinay Sajip (vinay.sajip) * (Python committer) | Date: 2011年08月27日 15:24 | |
Closing, as Andrey Vlasovskikh has agreed that this is a duplicate of #9205. |
|||
| msg143080 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2011年08月27日 15:37 | |
Note that #9205 fixed concurrent.futures, but not multiprocessing.Pool which is a different kettle of fish. |
|||
| msg221549 - (view) | Author: Markus Unterwaditzer (untitaker) | Date: 2014年06月25日 13:38 | |
Can this issue or #9205 be reopened as this particular instance of the problem doesn't seem to be resolved? I still seem to need the workaround from http://stackoverflow.com/a/1408476 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:59 | admin | set | github: 52543 |
| 2014年08月24日 01:49:59 | brian.curtin | set | nosy:
- brian.curtin |
| 2014年08月22日 20:55:07 | myint | set | nosy:
+ myint |
| 2014年06月25日 18:42:24 | ned.deily | set | nosy:
+ sbt |
| 2014年06月25日 13:38:04 | untitaker | set | nosy:
+ untitaker messages: + msg221549 |
| 2014年05月12日 13:58:09 | mdengler | set | nosy:
+ mdengler |
| 2011年08月27日 15:37:11 | pitrou | set | nosy:
+ pitrou messages: + msg143080 |
| 2011年08月27日 15:24:23 | vinay.sajip | set | status: open -> closed nosy: + vinay.sajip messages: + msg143077 resolution: duplicate |
| 2011年04月27日 14:18:58 | gkcn | set | nosy:
+ gkcn |
| 2010年08月27日 06:44:16 | gdb | set | nosy:
+ gdb |
| 2010年08月26日 13:48:44 | vlasovskikh | set | messages: + msg114976 |
| 2010年08月25日 13:30:55 | jnoller | set | messages: + msg114900 |
| 2010年08月25日 08:43:30 | asksol | set | messages: + msg114888 |
| 2010年08月24日 20:40:45 | asksol | set | messages: + msg114821 |
| 2010年08月24日 20:29:50 | brian.curtin | set | nosy:
+ asksol |
| 2010年08月24日 20:26:48 | Albert.Strasheim | set | messages: + msg114817 |
| 2010年08月24日 20:25:14 | Albert.Strasheim | set | nosy:
+ Albert.Strasheim |
| 2010年04月06日 20:35:08 | brian.curtin | set | nosy:
+ jnoller |
| 2010年04月06日 18:32:04 | vlasovskikh | set | files:
+ fix-sigint.diff keywords: + patch messages: + msg102481 |
| 2010年04月06日 18:23:24 | vlasovskikh | set | files: - test_pool_keyboardinterrupt.py |
| 2010年04月06日 18:21:41 | vlasovskikh | set | files:
+ test_map_keyboard_interrput.py messages: + msg102479 |
| 2010年04月03日 04:07:48 | vlasovskikh | set | messages: + msg102223 |
| 2010年04月03日 03:54:01 | brian.curtin | set | messages: + msg102222 |
| 2010年04月03日 03:45:53 | vlasovskikh | set | files:
+ test_pool_keyboardinterrupt.py messages: + msg102221 |
| 2010年04月03日 03:39:13 | brian.curtin | set | nosy:
+ brian.curtin messages: + msg102220 type: crash -> behavior stage: test needed |
| 2010年04月03日 03:37:14 | vlasovskikh | create | |