Skip to content

Commit 35bdb2d

Browse files
committed
Fixed some errors
1 parent cf08147 commit 35bdb2d

File tree

3 files changed

+48
-52
lines changed

3 files changed

+48
-52
lines changed

nipype/pipeline/plugins/callback_log.py

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,63 @@
33
"""Callback logger for recording workflow and node run stats
44
"""
55

6-
# Import packages
7-
import datetime
8-
import logging
96

107
# Log node stats function
118
def log_nodes_cb(node, status):
129
"""Function to record node run statistics to a log file as json
1310
dictionaries
11+
12+
Parameters
13+
----------
14+
node : nipype.pipeline.engine.Node
15+
the node being logged
16+
status : string
17+
acceptable values are 'start', 'end'; otherwise it is
18+
considered and error
19+
20+
Returns
21+
-------
22+
None
23+
this function does not return any values, it logs the node
24+
status info to the callback logger
1425
"""
1526

16-
# Init variables
17-
logger = logging.getLogger('callback')
27+
# Import packages
28+
import datetime
29+
import logging
30+
import json
1831

1932
# Check runtime profile stats
2033
if node.result is not None:
2134
try:
2235
runtime = node.result.runtime
2336
runtime_memory_gb = runtime.runtime_memory_gb
2437
runtime_threads = runtime.runtime_threads
25-
except:
26-
runtime_memory_gb = runtime_threads = 'Unkown'
38+
except AttributeError:
39+
runtime_memory_gb = runtime_threads = 'Unknown'
2740
else:
2841
runtime_memory_gb = runtime_threads = 'N/A'
2942

43+
# Init variables
44+
logger = logging.getLogger('callback')
45+
status_dict = {'name' : node.name,
46+
'id' : node._id,
47+
'estimated_memory_gb' : node._interface.estimated_memory_gb,
48+
'num_threads' : node._interface.num_threads}
49+
3050
# Check status and write to log
3151
# Start
3252
if status == 'start':
33-
message = '{"name":' + '"' + node.name + '"' + ',"id":' + '"' +\
34-
node._id + '"' + ',"start":' + '"' +str(datetime.datetime.now()) +\
35-
'"' + ',"estimated_memory_gb":' + str(node._interface.estimated_memory_gb) + \
36-
',"num_threads":' + str(node._interface.num_threads) + '}'
37-
38-
logger.debug(message)
53+
status_dict['start'] = str(datetime.datetime.now())
3954
# End
4055
elif status == 'end':
41-
message = '{"name":' + '"' + node.name + '"' + ',"id":' + '"' + \
42-
node._id + '"' + ',"finish":' + '"' + str(datetime.datetime.now()) + \
43-
'"' + ',"estimated_memory_gb":' + '"'+ str(node._interface.estimated_memory_gb) + \
44-
'"'+ ',"num_threads":' + '"'+ str(node._interface.num_threads) + '"'+ \
45-
',"runtime_threads":' + '"'+ str(runtime_threads) + '"'+ \
46-
',"runtime_memory_gb":' + '"'+ str(runtime_memory_gb) + '"' + '}'
47-
48-
logger.debug(message)
56+
status_dict['finish'] = str(datetime.datetime.now())
57+
status_dict['runtime_threads'] = runtime_threads
58+
status_dict['runtime_memory_gb'] = runtime_memory_gb
4959
# Other
5060
else:
51-
message = '{"name":' + '"' + node.name + '"' + ',"id":' + '"' + \
52-
node._id + '"' + ',"finish":' + '"' + str(datetime.datetime.now()) +\
53-
'"' + ',"estimated_memory_gb":' + str(node._interface.estimated_memory_gb) + \
54-
',"num_threads":' + str(node._interface.num_threads) + ',"error":"True"}'
61+
status_dict['finish'] = str(datetime.datetime.now())
62+
status_dict['error'] = True
5563

56-
logger.debug(message)
64+
# Dump string to log
65+
logger.debug(json.dumps(status_dict))

nipype/pipeline/plugins/multiproc.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ class MultiProcPlugin(DistributedPluginBase):
124124
Currently supported options are:
125125
126126
- non_daemon : boolean flag to execute as non-daemon processes
127-
- num_threads: maximum number of threads to be executed in parallel
128-
- estimated_memory_gb: maximum memory (in GB) that can be used at once.
127+
- n_procs: maximum number of threads to be executed in parallel
128+
- memory_gb: maximum memory (in GB) that can be used at once.
129129
130130
"""
131131

@@ -180,11 +180,8 @@ def _clear_task(self, taskid):
180180

181181
def _submit_job(self, node, updatehash=False):
182182
self._taskid += 1
183-
try:
184-
if node.inputs.terminal_output == 'stream':
185-
node.inputs.terminal_output = 'allatonce'
186-
except:
187-
pass
183+
if node.inputs.terminal_output == 'stream':
184+
node.inputs.terminal_output = 'allatonce'
188185

189186
self._taskresult[self._taskid] = \
190187
self.pool.apply_async(run_node,
@@ -282,8 +279,10 @@ def _send_procs_to_workers(self, updatehash=False, graph=None):
282279
% self.procs[jobid])
283280
try:
284281
self.procs[jobid].run()
285-
except Exception:
286-
self._clean_queue(jobid, graph)
282+
except:
283+
etype, eval, etr = sys.exc_info()
284+
formatted_exc = format_exception(etype, eval, etr)
285+
logger.debug('Traceback:\n%s' % '\n'.join(formatted_exc))
287286
self._task_finished_cb(jobid)
288287
self._remove_node_dirs()
289288

nipype/utils/draw_gantt_chart.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,10 @@ def create_event_dict(start_time, nodes_list):
4343
events = {}
4444
for node in nodes_list:
4545
# Format node fields
46-
try:
47-
estimated_threads = float(node['num_threads'])
48-
except:
49-
estimated_threads = 1
50-
try:
51-
estimated_memory_gb = float(node['estimated_memory_gb'])
52-
except:
53-
estimated_memory_gb = 1.0
54-
try:
55-
runtime_threads = float(node['runtime_threads'])
56-
except:
57-
runtime_threads = 0
58-
try:
59-
runtime_memory_gb = float(node['runtime_memory_gb'])
60-
except:
61-
runtime_memory_gb = 0.0
46+
estimated_threads = int(node.get('num_threads'), 1)
47+
estimated_memory_gb = float(node.get('estimated_memory_gb', 1.0))
48+
runtime_threads = int(node.get('runtime_threads'), 0)
49+
runtime_memory_gb = float(node.get('runtime_memory_gb', 0.0))
6250

6351
# Init and format event-based nodes
6452
node['estimated_threads'] = estimated_threads
@@ -119,7 +107,7 @@ def log_to_dict(logfile):
119107
node = None
120108
try:
121109
node = json.loads(l)
122-
except Exception:
110+
except ValueError:
123111
pass
124112

125113
if not node:

0 commit comments

Comments
 (0)