Skip to content

Commit f403708

Browse files
author
Daniel Haehn
committed
Introduce the non-daemon process pool as an alternative to the original multiprocessing pool. This adds support for hierarchical multiprocessing (child classes can use multiprocessing again).
The code is based on the following StackOverflow answer: http://stackoverflow.com/a/8963618/1183453
1 parent 4480f17 commit f403708

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

nipype/pipeline/plugins/multiproc.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
"""Parallel workflow execution via multiprocessing
4+
5+
Support for child processes running as non-daemons based on
6+
http://stackoverflow.com/a/8963618/1183453
47
"""
58

6-
from multiprocessing import Pool
9+
from multiprocessing import Process
10+
from multiprocessing.pool import Pool
711
from traceback import format_exception
812
import sys
913

@@ -19,6 +23,20 @@ def run_node(node, updatehash):
1923
result['result'] = node.result
2024
return result
2125

26+
class NonDaemonProcess(Process):
27+
"""A non-daemon process to support internal multiprocessing.
28+
"""
29+
def _get_daemon(self):
30+
return False
31+
def _set_daemon(self, value):
32+
pass
33+
daemon = property(_get_daemon, _set_daemon)
34+
35+
class NonDaemonPool(Pool):
36+
"""A process pool with non-daemon processes.
37+
"""
38+
Process = NonDaemonProcess
39+
2240
class MultiProcPlugin(DistributedPluginBase):
2341
"""Execute workflow with multiprocessing
2442

0 commit comments

Comments
 (0)