code: def handle_unhandled_exception(exc_type, exc_value, exc_traceback):
      
      if issubclass(exc_type, KeyboardInterrupt):
          # call the default excepthook saved at __excepthook__
          sys.__excepthook__(exc_type, exc_value, exc_traceback)
          return
      logger = logging.getLogger(__name__) # type: ignore
      logger.critical("Unhandled exception", exc_info=(exc_type, exc_value, exc_traceback))
docs: Handler for unhandled exceptions that will write to the logs