- logger.exception(f'Unhandled top level {exc_type}',
- exc_info=(exc_type, exc_value, exc_traceback))
- traceback.print_exception(exc_type, exc_value, exc_traceback)
- if config.config['debug_unhandled_exceptions']:
- logger.info("Invoking the debugger...")
- pdb.pm()
+ else:
+ if (
+ not sys.stderr.isatty() or
+ not sys.stdin.isatty()
+ ):
+ # stdin or stderr is redirected, just do the normal thing
+ original_hook(exc_type, exc_value, exc_tb)
+ else:
+ # a terminal is attached and stderr is not redirected, maybe debug.
+ import traceback
+ traceback.print_exception(exc_type, exc_value, exc_tb)
+ if config.config['debug_unhandled_exceptions']:
+ import pdb
+ logger.info("Invoking the debugger...")
+ pdb.pm()
+ else:
+ original_hook(exc_type, exc_value, exc_tb)