Changeset 1558 for trunk/GSASIIpath.py


Ignore:
Timestamp:
Nov 2, 2014 10:11:53 PM (8 years ago)
Author:
toby
Message:

add some debug options with pdb and IPython

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpath.py

    r1557 r1558  
    1313Other routines will update GSASII from the subversion server if svn can be
    1414found.
     15
     16Accesses configuration options, as defined in config.py
    1517'''
    1618
     
    307309    sys.exit()
    308310
     311def IPyBreak():
     312    '''A routine that invokes an IPython session at the calling location
     313    This routine is only used when debug=True is set in config.py
     314    '''
     315    savehook = sys.excepthook # save the exception hook
     316    from IPython.terminal.embed import InteractiveShellEmbed
     317    import inspect
     318    ipshell = InteractiveShellEmbed()
     319
     320    frame = inspect.currentframe().f_back
     321    msg   = 'Entering IPython console inside {0.f_code.co_filename} at line {0.f_lineno}'.format(frame)
     322    ipshell(msg,stack_depth=2) # Go up one level, to see the calling routine
     323    sys.excepthook = savehook # reset IPython's change to the exception hook
     324
     325def exceptHook(*args):
     326    '''A routine to be called when an exception occurs. It prints the traceback
     327    with fancy formatting and then calls an IPython shell with the environment
     328    of the exception location.
     329   
     330    This routine is only used when debug=True is set in config.py   
     331    '''
     332    from IPython.core import ultratb
     333    ultratb.FormattedTB(call_pdb=False,color_scheme='LightBG')(*args)
     334    from IPython.terminal.embed import InteractiveShellEmbed
     335    import inspect
     336    frame = inspect.getinnerframes(args[2])[-1][0]
     337    msg   = 'Entering IPython console at {0.f_code.co_filename} at line {0.f_lineno}'.format(frame)
     338    InteractiveShellEmbed(banner1=msg)(local_ns=frame.f_locals,global_ns=frame.f_globals)
     339
     340def DoNothing():
     341    '''A routine that does nothing. This is called in place of IPyBreak and pdbBreak
     342    except when the debug option is set True in config.py
     343    '''
     344    pass
     345
     346if GetConfigValue('debug'):
     347    print 'Debug on: IPython: Exceptions and G2path.IPyBreak(); pdb: G2path.pdbBreak()'
     348    sys.excepthook = exceptHook
     349    import pdb
     350    pdbBreak = pdb.set_trace
     351else:
     352    IPyBreak = DoNothing
     353    pdbBreak = DoNothing
     354   
    309355if __name__ == '__main__':
    310356    import subprocess
Note: See TracChangeset for help on using the changeset viewer.