Skip to content

Commit a4e3ae6

Browse files
committed
Added try-blocks around the runtime profile stats in callback logger
1 parent c074299 commit a4e3ae6

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

nipype/pipeline/plugins/callback_log.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,43 @@
22
import logging
33

44
def log_nodes_cb(node, status, result=None):
5+
'''
6+
'''
7+
8+
# Init variables
59
logger = logging.getLogger('callback')
10+
11+
# Check runtime profile stats
612
if result is None:
713
node_mem = cmd_mem = run_seconds = cmd_threads = 'N/A'
814
else:
9-
node_mem = result['node_memory']
10-
cmd_mem = result['cmd_memory']
11-
run_seconds = result['run_seconds']
12-
cmd_threads = result['cmd_threads']
15+
try:
16+
node_mem = result['node_memory']
17+
except KeyError:
18+
node_mem = 'Unknown'
19+
try:
20+
cmd_mem = result['cmd_memory']
21+
except KeyError:
22+
cmd_mem = 'Unknown'
23+
try:
24+
run_seconds = result['run_seconds']
25+
except KeyError:
26+
run_seconds = 'Unknown'
27+
try:
28+
cmd_threads = result['cmd_threads']
29+
except:
30+
cmd_threads = 'Unknown'
31+
32+
# Check status and write to log
33+
# Start
1334
if status == 'start':
1435
message = '{"name":' + '"' + node.name + '"' + ',"id":' + '"' +\
1536
node._id + '"' + ',"start":' + '"' +str(datetime.datetime.now()) +\
1637
'"' + ',"estimated_memory":' + str(node._interface.estimated_memory) + ',"num_threads":' \
1738
+ str(node._interface.num_threads) + '}'
1839

1940
logger.debug(message)
20-
41+
# End
2142
elif status == 'end':
2243
message = '{"name":' + '"' + node.name + '"' + ',"id":' + '"' + \
2344
node._id + '"' + ',"finish":' + '"' + str(datetime.datetime.now()) + \
@@ -29,7 +50,7 @@ def log_nodes_cb(node, status, result=None):
2950
',"run_seconds":' + '"'+ str(run_seconds) + '"'+ '}'
3051

3152
logger.debug(message)
32-
53+
# Other
3354
else:
3455
message = '{"name":' + '"' + node.name + '"' + ',"id":' + '"' + \
3556
node._id + '"' + ',"finish":' + '"' + str(datetime.datetime.now()) +\

nipype/pipeline/plugins/tests/test_multiproc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ def test_do_not_use_more_threads_then_specified():
212212
pipe.connect(n3, 'output1', n4, 'input2')
213213
n1.inputs.input1 = 10
214214
pipe.config['execution']['poll_sleep_duration'] = 1
215-
pipe.run(plugin='ResourceMultiProc', plugin_args={'n_procs': max_threads, 'status_callback': log_nodes_cb})
215+
pipe.run(plugin='ResourceMultiProc', plugin_args={'n_procs': max_threads,
216+
'status_callback': log_nodes_cb})
216217

217218
nodes, last_node = draw_gantt_chart.log_to_json(LOG_FILENAME)
218219
#usage in every second

0 commit comments

Comments
 (0)