Skip to content

Instantly share code, notes, and snippets.

@4ft35t
Forked from notsobad/autopdb.py
Last active June 25, 2018 06:03
Show Gist options
  • Save 4ft35t/ab6ff12f61a040235343 to your computer and use it in GitHub Desktop.
Save 4ft35t/ab6ff12f61a040235343 to your computer and use it in GitHub Desktop.

Revisions

  1. 4ft35t revised this gist Jun 25, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion autopdb.py
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    original: http://code.activestate.com/recipes/65287/
    Put this in python module dir, on mac: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
    or /usr/local/lib/python3.*/site-packages
    Run your script this way:
    >> python -m autopdb /path/script.py
    @@ -25,7 +26,7 @@ def info(type, value, tb):
    import traceback, pdb
    # we are NOT in interactive mode, print the exception...
    traceback.print_exception(type, value, tb)
    print
    print()
    # ...then start the debugger in post-mortem mode.
    pdb.pm()

  2. 4ft35t revised this gist Jun 25, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion autopdb.py
    Original file line number Diff line number Diff line change
    @@ -31,4 +31,5 @@ def info(type, value, tb):

    sys.excepthook = info

    execfile(sys.argv[1])
    # execfile(sys.argv[1]) # py2
    exec(open(sys.argv[1], 'rb').read()) # py3
  3. @notsobad notsobad renamed this gist Oct 23, 2014. 1 changed file with 11 additions and 4 deletions.
    15 changes: 11 additions & 4 deletions sitecustomize.py → autopdb.py
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,13 @@
    #
    # original: http://code.activestate.com/recipes/65287/
    #
    '''
    original: http://code.activestate.com/recipes/65287/
    Put this in python module dir, on mac: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
    Run your script this way:
    >> python -m autopdb /path/script.py
    '''


    # place in lib/python2.x/sitecustomize.py
    import bdb
    import sys

    @@ -25,3 +30,5 @@ def info(type, value, tb):
    pdb.pm()

    sys.excepthook = info

    execfile(sys.argv[1])
  4. @rctay rctay revised this gist Aug 1, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions sitecustomize.py
    Original file line number Diff line number Diff line change
    @@ -3,13 +3,15 @@
    #

    # place in lib/python2.x/sitecustomize.py
    import bdb
    import sys

    def info(type, value, tb):
    if hasattr(sys, 'ps1') \
    or not sys.stdin.isatty() \
    or not sys.stdout.isatty() \
    or not sys.stderr.isatty() \
    or issubclass(type, bdb.BdbQuit) \
    or issubclass(type, SyntaxError):
    # we are in interactive mode or we don't have a tty-like
    # device, so we call the default hook
  5. @rctay rctay revised this gist Jul 24, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sitecustomize.py
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    # original: http://code.activestate.com/recipes/65287/
    #

    # code snippet, to be included in 'sitecustomize.py'
    # place in lib/python2.x/sitecustomize.py
    import sys

    def info(type, value, tb):
  6. @rctay rctay revised this gist Jul 24, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sitecustomize.py
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ def info(type, value, tb):
    or not sys.stdin.isatty() \
    or not sys.stdout.isatty() \
    or not sys.stderr.isatty() \
    or type == SyntaxError:
    or issubclass(type, SyntaxError):
    # we are in interactive mode or we don't have a tty-like
    # device, so we call the default hook
    sys.__excepthook__(type, value, tb)
  7. @rctay rctay revised this gist Jul 24, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion sitecustomize.py
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,8 @@ def info(type, value, tb):
    if hasattr(sys, 'ps1') \
    or not sys.stdin.isatty() \
    or not sys.stdout.isatty() \
    or not sys.stderr.isatty():
    or not sys.stderr.isatty() \
    or type == SyntaxError:
    # we are in interactive mode or we don't have a tty-like
    # device, so we call the default hook
    sys.__excepthook__(type, value, tb)
  8. @rctay rctay revised this gist Jul 24, 2012. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion sitecustomize.py
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,10 @@
    import sys

    def info(type, value, tb):
    if hasattr(sys, 'ps1') or not sys.stderr.isatty():
    if hasattr(sys, 'ps1') \
    or not sys.stdin.isatty() \
    or not sys.stdout.isatty() \
    or not sys.stderr.isatty():
    # we are in interactive mode or we don't have a tty-like
    # device, so we call the default hook
    sys.__excepthook__(type, value, tb)
  9. @rctay rctay revised this gist Jul 24, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions sitecustomize.py
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    # original: http://code.activestate.com/recipes/65287/
    #

    # code snippet, to be included in 'sitecustomize.py'
    import sys

    def info(type, value, tb):
  10. @rctay rctay created this gist Jul 24, 2012.
    20 changes: 20 additions & 0 deletions sitecustomize.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #
    # original: http://code.activestate.com/recipes/65287/
    #

    import sys

    def info(type, value, tb):
    if hasattr(sys, 'ps1') or not sys.stderr.isatty():
    # we are in interactive mode or we don't have a tty-like
    # device, so we call the default hook
    sys.__excepthook__(type, value, tb)
    else:
    import traceback, pdb
    # we are NOT in interactive mode, print the exception...
    traceback.print_exception(type, value, tb)
    print
    # ...then start the debugger in post-mortem mode.
    pdb.pm()

    sys.excepthook = info