crash.py 809 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import argparse
  2. import sys
  3. import time
  4. from IPython.core import ultratb
  5. from .mod import modfunc
  6. def one():
  7. modfunc(two) # aaa
  8. def two():
  9. three(42)
  10. def three(x):
  11. raise RuntimeError(f"Kaboom! I'm dead: {x}")
  12. def main():
  13. hooks = {
  14. "default": lambda: sys.excepthook,
  15. "ultratb_color": lambda: ultratb.ColorTB(ostream=sys.stderr),
  16. "ultratb_verbose": lambda: ultratb.VerboseTB(ostream=sys.stderr),
  17. }
  18. parser = argparse.ArgumentParser()
  19. parser.add_argument("hook", choices=sorted(hooks), default="default")
  20. args = parser.parse_args()
  21. sys.excepthook = hooks[args.hook]()
  22. print("__name__ =", __name__)
  23. print("__file__ =", __file__)
  24. time.time = lambda: 1531996624.0 # Freeze time
  25. sys.executable = "<traceback test>"
  26. one()