Skip to content

Commit 70b2084

Browse files
authored
Merge pull request #1885 from mgxd/enh/crashtxt
ENH: config option to write crashfiles in plain text
2 parents 8119d78 + fca5ff8 commit 70b2084

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

doc/users/config_file.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,15 @@ Execution
137137
schedulers the default is set to 2 seconds.
138138

139139
*xvfb_max_wait*
140-
Maximum time (in seconds) to wait for Xvfb to start, if the _redirect_x parameter of an Interface is True.
141-
140+
Maximum time (in seconds) to wait for Xvfb to start, if the _redirect_x
141+
parameter of an Interface is True.
142+
143+
*crashfile_format*
144+
This option controls the file type of any crashfile generated. Pklz
145+
crashfiles allow interactive debugging and rerunning of nodes, while text
146+
crashfiles allow portability across machines and shorter load time.
147+
(possible values: ``pklz`` and ``txt``; default value: ``pklz``)
148+
142149
Example
143150
~~~~~~~
144151

nipype/pipeline/plugins/base.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
from ... import logging
26-
from ...utils.filemanip import savepkl, loadpkl
26+
from ...utils.filemanip import savepkl, loadpkl, crash2txt
2727
from ...utils.misc import str2bool
2828
from ..engine.utils import (nx, dfs_preorder, topological_sort)
2929
from ..engine import MapNode
@@ -58,7 +58,7 @@ def report_crash(node, traceback=None, hostname=None):
5858
exc_traceback)
5959
timeofcrash = strftime('%Y%m%d-%H%M%S')
6060
login_name = getpass.getuser()
61-
crashfile = 'crash-%s-%s-%s-%s.pklz' % (timeofcrash,
61+
crashfile = 'crash-%s-%s-%s-%s' % (timeofcrash,
6262
login_name,
6363
name,
6464
str(uuid.uuid4()))
@@ -68,10 +68,16 @@ def report_crash(node, traceback=None, hostname=None):
6868
if not os.path.exists(crashdir):
6969
os.makedirs(crashdir)
7070
crashfile = os.path.join(crashdir, crashfile)
71+
if node.config['execution']['crashfile_format'].lower() in ['text', 'txt']:
72+
crashfile += '.txt'
73+
else:
74+
crashfile += '.pklz'
7175
logger.info('Saving crash info to %s' % crashfile)
7276
logger.info(''.join(traceback))
73-
savepkl(crashfile, dict(node=node, traceback=traceback))
74-
# np.savez(crashfile, node=node, traceback=traceback)
77+
if node.config['execution']['crashfile_format'].lower() in ['text', 'txt']:
78+
crash2txt(crashfile, dict(node=node, traceback=traceback))
79+
else:
80+
savepkl(crashfile, dict(node=node, traceback=traceback))
7581
return crashfile
7682

7783

nipype/pipeline/plugins/tests/test_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def test_report_crash():
2626
mock_node._id = 'an_id'
2727
mock_node.config = {
2828
'execution' : {
29-
'crashdump_dir' : '.'
29+
'crashdump_dir' : '.',
30+
'crashfile_format' : 'pklz',
3031
}
3132
}
3233

nipype/utils/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
remove_unnecessary_outputs = true
5656
try_hard_link_datasink = true
5757
single_thread_matlab = true
58+
crashfile_format = pklz
5859
stop_on_first_crash = false
5960
stop_on_first_rerun = false
6061
use_relative_paths = false

nipype/utils/filemanip.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,18 @@ def loadpkl(infile):
531531
return unpkl
532532

533533

534+
def crash2txt(filename, record):
535+
""" Write out plain text crash file """
536+
with open(filename, 'w') as fp:
537+
if 'node' in record:
538+
node = record['node']
539+
fp.write('Node: {}\n'.format(node.fullname))
540+
fp.write('Working directory: {}\n'.format(node.output_dir()))
541+
fp.write('\n')
542+
fp.write('Node inputs:\n{}\n'.format(node.inputs))
543+
fp.write(''.join(record['traceback']))
544+
545+
534546
def savepkl(filename, record):
535547
if filename.endswith('pklz'):
536548
pkl_file = gzip.open(filename, 'wb')

0 commit comments

Comments
 (0)