Skip to content

ENH: config option to write crashfiles in plain text #1885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions doc/users/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,15 @@ Execution
schedulers the default is set to 2 seconds.

*xvfb_max_wait*
Maximum time (in seconds) to wait for Xvfb to start, if the _redirect_x parameter of an Interface is True.

Maximum time (in seconds) to wait for Xvfb to start, if the _redirect_x
parameter of an Interface is True.

*crashfile_format*
This option controls the file type of any crashfile generated. Pklz
crashfiles allow interactive debugging and rerunning of nodes, while text
crashfiles allow portability across machines and shorter load time.
(possible values: ``pklz`` and ``txt``; default value: ``pklz``)

Example
~~~~~~~

Expand Down
14 changes: 10 additions & 4 deletions nipype/pipeline/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


from ... import logging
from ...utils.filemanip import savepkl, loadpkl
from ...utils.filemanip import savepkl, loadpkl, crash2txt
from ...utils.misc import str2bool
from ..engine.utils import (nx, dfs_preorder, topological_sort)
from ..engine import MapNode
Expand Down Expand Up @@ -58,7 +58,7 @@ def report_crash(node, traceback=None, hostname=None):
exc_traceback)
timeofcrash = strftime('%Y%m%d-%H%M%S')
login_name = getpass.getuser()
crashfile = 'crash-%s-%s-%s-%s.pklz' % (timeofcrash,
crashfile = 'crash-%s-%s-%s-%s' % (timeofcrash,
login_name,
name,
str(uuid.uuid4()))
Expand All @@ -68,10 +68,16 @@ def report_crash(node, traceback=None, hostname=None):
if not os.path.exists(crashdir):
os.makedirs(crashdir)
crashfile = os.path.join(crashdir, crashfile)
if node.config['execution']['crashfile_format'].lower() in ['text', 'txt']:
crashfile += '.txt'
else:
crashfile += '.pklz'
logger.info('Saving crash info to %s' % crashfile)
logger.info(''.join(traceback))
savepkl(crashfile, dict(node=node, traceback=traceback))
# np.savez(crashfile, node=node, traceback=traceback)
if node.config['execution']['crashfile_format'].lower() in ['text', 'txt']:
crash2txt(crashfile, dict(node=node, traceback=traceback))
else:
savepkl(crashfile, dict(node=node, traceback=traceback))
return crashfile


Expand Down
3 changes: 2 additions & 1 deletion nipype/pipeline/plugins/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def test_report_crash():
mock_node._id = 'an_id'
mock_node.config = {
'execution' : {
'crashdump_dir' : '.'
'crashdump_dir' : '.',
'crashfile_format' : 'pklz',
}
}

Expand Down
1 change: 1 addition & 0 deletions nipype/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
remove_unnecessary_outputs = true
try_hard_link_datasink = true
single_thread_matlab = true
crashfile_format = pklz
stop_on_first_crash = false
stop_on_first_rerun = false
use_relative_paths = false
Expand Down
12 changes: 12 additions & 0 deletions nipype/utils/filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,18 @@ def loadpkl(infile):
return unpkl


def crash2txt(filename, record):
""" Write out plain text crash file """
with open(filename, 'w') as fp:
if 'node' in record:
node = record['node']
fp.write('Node: {}\n'.format(node.fullname))
fp.write('Working directory: {}\n'.format(node.output_dir()))
fp.write('\n')
fp.write('Node inputs:\n{}\n'.format(node.inputs))
fp.write(''.join(record['traceback']))


def savepkl(filename, record):
if filename.endswith('pklz'):
pkl_file = gzip.open(filename, 'wb')
Expand Down