@contextlib.contextmanager
def disabled_excepthook():
 old_excepthook = sys.excepthook
 sys.excepthook = sys.__excepthook__
 try:
  (yield)
 finally:
  if (sys.excepthook is sys.__excepthook__):
   sys.excepthook = old_excepthook

@ contextlib . contextmanager def disabled_excepthook ( ) : old_excepthook = sys . excepthook sys . excepthook = sys . __excepthook__ try : ( yield ) finally : if ( sys . excepthook is sys . __excepthook__ ) : sys . excepthook = old_excepthook
run code with the exception hook temporarily disabled .