Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. import pdb, traceback, sys
  2.  
  3. def bombs():
  4. a = []
  5. print a[0]
  6.  
  7. if __name__ == '__main__':
  8. try:
  9. bombs()
  10. except:
  11. type, value, tb = sys.exc_info()
  12. traceback.print_exc()
  13. pdb.post_mortem(tb)
  14.  
  15. import traceback, sys, code
  16.  
  17. def bombs():
  18. a = []
  19. print a[0]
  20.  
  21. if __name__ == '__main__':
  22. try:
  23. bombs()
  24. except:
  25. type, value, tb = sys.exc_info()
  26. traceback.print_exc()
  27. last_frame = lambda tb=tb: last_frame(tb.tb_next) if tb.tb_next else tb
  28. frame = last_frame().tb_frame
  29. ns = dict(frame.f_globals)
  30. ns.update(frame.f_locals)
  31. code.interact(local=ns)
  32.  
  33. python -m pdb -c continue myscript.py
  34.  
  35. import sys
  36.  
  37. def info(type, value, tb):
  38. if hasattr(sys, 'ps1') or not sys.stderr.isatty():
  39. # we are in interactive mode or we don't have a tty-like
  40. # device, so we call the default hook
  41. sys.__excepthook__(type, value, tb)
  42. else:
  43. import traceback, pdb
  44. # we are NOT in interactive mode, print the exception...
  45. traceback.print_exception(type, value, tb)
  46. print
  47. # ...then start the debugger in post-mortem mode.
  48. # pdb.pm() # deprecated
  49. pdb.post_mortem(tb) # more "modern"
  50.  
  51. sys.excepthook = info
  52.  
  53. testlist = [1,2,3,4,5, 0]
  54.  
  55. prev_i = None
  56. for i in testlist:
  57. if not prev_i:
  58. prev_i = i
  59. else:
  60. result = prev_i/i
  61.  
  62. PS D:> python -i debugtest.py
  63. Traceback (most recent call last):
  64. File "debugtest.py", line 10, in <module>
  65. result = prev_i/i
  66. ZeroDivisionError: integer division or modulo by zero
  67. >>>
  68. >>>
  69. >>> prev_i
  70. 1
  71. >>> i
  72. 0
  73. >>>
  74.  
  75. python myscript.py arg1 arg2
  76.  
  77. ipython --pdb myscript.py -- arg1 arg2
  78.  
  79. python -m mymodule arg1 arg2
  80.  
  81. ipython --pdb -m mymodule -- arg1 arg2
  82.  
  83. import pdb ; pdb.set_trace()
  84.  
  85. python -m pdb -c c <script name>
  86.  
  87. python -m mymodule
  88.  
  89. PYTHONPATH="." python -m pdb -c c mymodule/__main__.py
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement