6
6
import nipype .pipeline .engine as pe
7
7
from nipype .interfaces .utility import Function
8
8
9
- def dummyFunction (filename ):
10
- '''
11
- This function writes the value 45 to the given filename.
12
- '''
13
- j = 0
14
- for i in range (0 , 10 ):
15
- j += i
16
-
17
- # j is now 45 (0+1+2+3+4+5+6+7+8+9)
18
-
19
- with open (filename , 'w' ) as f :
20
- f .write (str (j ))
21
9
22
10
def mytestFunction (insum = 0 ):
23
11
'''
@@ -41,6 +29,19 @@ def mytestFunction(insum=0):
41
29
# list of tempFiles
42
30
f = [None ] * numberOfThreads
43
31
32
+ def dummyFunction (filename ):
33
+ '''
34
+ This function writes the value 45 to the given filename.
35
+ '''
36
+ j = 0
37
+ for i in range (0 , 10 ):
38
+ j += i
39
+
40
+ # j is now 45 (0+1+2+3+4+5+6+7+8+9)
41
+
42
+ with open (filename , 'w' ) as f :
43
+ f .write (str (j ))
44
+
44
45
for n in xrange (numberOfThreads ):
45
46
46
47
# mark thread as alive
@@ -72,7 +73,7 @@ def mytestFunction(insum=0):
72
73
# here, all processes are done
73
74
74
75
# read in all temp files and sum them up
75
- total = 0
76
+ total = insum
76
77
for file in f :
77
78
with open (file ) as fd :
78
79
total += int (fd .read ())
@@ -105,7 +106,7 @@ def run_multiproc_nondaemon_with_flag(nondaemon_flag):
105
106
pipe .base_dir = os .getcwd ()
106
107
f1 .inputs .insum = 0
107
108
108
- pipe .config = {'execution' : {'stop_on_first_error ' : True }}
109
+ pipe .config = {'execution' : {'stop_on_first_crash ' : True }}
109
110
# execute the pipe using the MultiProc plugin with 2 processes and the non_daemon flag
110
111
# to enable child processes which start other multiprocessing jobs
111
112
execgraph = pipe .run (plugin = "MultiProc" ,
@@ -117,8 +118,7 @@ def run_multiproc_nondaemon_with_flag(nondaemon_flag):
117
118
result = node .get_output ('sum_out' )
118
119
os .chdir (cur_dir )
119
120
rmtree (temp_dir )
120
- if nondaemon_flag :
121
- yield assert_equal , result , 180 # n_procs (2) * numberOfThreads (2) * 45 == 180
121
+ return result
122
122
123
123
124
124
def test_run_multiproc_nondaemon_false ():
@@ -130,15 +130,15 @@ def test_run_multiproc_nondaemon_false():
130
130
non_daemon flag is on.
131
131
'''
132
132
shouldHaveFailed = False
133
-
134
133
try :
135
- # with nondaemon_flag = False, the execution should fail
136
- run_multiproc_nondaemon_with_flag (False )
134
+ # with nondaemon_flag = False, the execution should fail
135
+ run_multiproc_nondaemon_with_flag (False )
137
136
except :
138
- shouldHaveFailed = True
137
+ shouldHaveFailed = True
139
138
yield assert_true , shouldHaveFailed
140
139
141
140
def test_run_multiproc_nondaemon_true ():
142
141
# with nondaemon_flag = True, the execution should succeed
143
- run_multiproc_nondaemon_with_flag (True )
144
-
142
+ result = run_multiproc_nondaemon_with_flag (True )
143
+ yield assert_equal , result , 180 # n_procs (2) * numberOfThreads (2) * 45 == 180
144
+
0 commit comments