Skip to content

Commit 25f5e2c

Browse files
committed
Merge pull request #961 from satra/enh/pdb
enh: add debugging mode to nipype display crash
2 parents 441554c + 6bf092b commit 25f5e2c

File tree

2 files changed

+61
-27
lines changed

2 files changed

+61
-27
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Next Release
3131
* ENH: Added ANTS based openfmri workflow
3232
* ENH: MapNode now supports flattening of nested lists
3333
* ENH: Support for headless mode using Xvfb
34+
* ENH: nipype_display_crash has a debugging mode
3435
* FIX: MRTrix tracking algorithms were ignoring mask parameters.
3536
* FIX: FNIRT registration pathway and associated OpenFMRI example script
3637
* FIX: spm12b compatibility for Model estimate

bin/nipype_display_crash

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,86 @@
11
#!/usr/bin/env python
22
"""Displays crash information from Nipype crash files. For certain crash files,
33
one can rerun a failed node in a temp directory.
4-
"""
54
6-
import argparse
7-
from nipype.utils.filemanip import loadcrash
5+
Examples:
6+
7+
nipype_display_crash crashfile.pklz
8+
nipype_display_crash crashfile.pklz -r -i
9+
nipype_display_crash crashfile.pklz -r -i
10+
11+
"""
812

9-
def display_crash_files(crashfile, rerun):
13+
def display_crash_files(crashfile, rerun, debug, directory):
1014
"""display crash file content and rerun if required"""
1115

16+
from nipype.utils.filemanip import loadcrash
1217
crash_data = loadcrash(crashfile)
1318
node = None
1419
if 'node' in crash_data:
1520
node = crash_data['node']
1621
tb = crash_data['traceback']
17-
print "\n"
18-
print "File: %s"%crashfile
22+
print("\n")
23+
print("File: %s" % crashfile)
1924
if node:
20-
print "Node: %s"%node
25+
print("Node: %s" % node)
2126
if node.base_dir:
22-
print "Working directory: %s"%node.output_dir()
27+
print("Working directory: %s" % node.output_dir())
2328
else:
24-
print "Node crashed before execution"
25-
print "\n"
26-
print "Node inputs:"
27-
print node.inputs
28-
print "\n"
29-
print "Traceback: "
30-
print ''.join(tb)
31-
print "\n"
29+
print("Node crashed before execution")
30+
print("\n")
31+
print("Node inputs:")
32+
print(node.inputs)
33+
print("\n")
34+
print("Traceback: ")
35+
print(''.join(tb))
36+
print ("\n")
3237

3338
if rerun:
3439
if node is None:
35-
print "No node in crashfile. Cannot rerun"
40+
print("No node in crashfile. Cannot rerun")
3641
return
37-
print "Rerunning node"
38-
node.base_dir = None
42+
print("Rerunning node")
43+
node.base_dir = directory
3944
node.config = {'execution': {'crashdump_dir': '/tmp'}}
40-
node.run()
41-
print "\n"
45+
try:
46+
node.run()
47+
except:
48+
if debug and debug != 'ipython':
49+
import pdb
50+
pdb.post_mortem()
51+
else:
52+
raise
53+
print("\n")
4254

4355
if __name__ == "__main__":
44-
parser = argparse.ArgumentParser(prog='nipype_display_crash',
45-
description=__doc__)
56+
from argparse import ArgumentParser, RawTextHelpFormatter
57+
defstr = ' (default %(default)s)'
58+
parser = ArgumentParser(prog='nipype_display_crash',
59+
description=__doc__,
60+
formatter_class=RawTextHelpFormatter)
4661
parser.add_argument('crashfile', metavar='f', type=str,
47-
help='crash file to display')
62+
help='crash file to display')
4863
parser.add_argument('-r','--rerun', dest='rerun',
4964
default=False, action="store_true",
50-
help='rerun crashed node')
65+
help='rerun crashed node' + defstr)
66+
group = parser.add_mutually_exclusive_group()
67+
group.add_argument('-d','--debug', dest='debug',
68+
default=False, action="store_true",
69+
help='enable python debugger when re-executing' + defstr)
70+
group.add_argument('-i','--ipydebug', dest='ipydebug',
71+
default=False, action="store_true",
72+
help='enable ipython debugger when re-executing' + defstr)
73+
parser.add_argument('--dir', dest='directory',
74+
default=None,
75+
help='Directory to run the node in' + defstr)
5176
args = parser.parse_args()
52-
53-
display_crash_files(args.crashfile, args.rerun)
77+
print args.debug, args.ipydebug
78+
debug = 'ipython' if args.ipydebug else args.debug
79+
if debug == 'ipython':
80+
import sys
81+
from IPython.core import ultratb
82+
sys.excepthook = ultratb.FormattedTB(mode='Verbose',
83+
color_scheme='Linux',
84+
call_pdb=1)
85+
display_crash_files(args.crashfile, args.rerun,
86+
debug, args.directory)

0 commit comments

Comments
 (0)