def __exit__(self, exc_type, exc_value, traceback):
        if exc_value:
            # An exception occurred during execution, so run the teardown callbacks. We use a lock here since multiple
            # threads could raise exceptions at the same time and we only want to execute these once.
            with self._handling_lock:
                if not isinstance(exc_value, (SystemExit, AppTeardown, KeyboardInterrupt)):
                    # It is not very useful to log the SystemExit exception since it is raised by sys.exit(), and thus
                    # application exit is completely expected.
                    self._logger.exception('Unhandled exception handler caught exception.')

                while not self._teardown_callback_stack.empty():
                    callback, args, kwargs = self._teardown_callback_stack.get()
                    self._logger.debug('Executing teardown callback: {}', callback)
                    try:
                        callback(*args, **kwargs)
                    except:  # pylint: disable=bare-except
                        # Also catch any exception that occurs during a teardown callback and log it.
                        self._teardown_callback_raised_exception = True
                        self._logger.exception('Exception raised by teardown callback {}', callback)

                self._handled_exceptions.put(exc_value)

        if current_thread() is main_thread():
            # The usage of this class on the main thread is a special case since only exceptions raised on the main
            # thread may affect the exit code of the overall application. Any unhandled exceptions raised on child
            # threads will only interrupt execution on that particular thread.
            #
            # This main-thread-only code path serves to ensure that exceptions raised on child threads during a `with
            # unhandled_exception_handler` block will also raise an exception on the main thread upon exit of the main
            # thread's `with unhandled_exception_handler` block. This ensures we will set a failing exit code even if
            # an exception is raised on a child thread.
            #
            # Note: this only works for child threads protected by the UnhandledExceptionHandler (e.g., an instance of
            # a SafeThread).
            #
            # We check the self._handled_exceptions queue to see if there was an exception that we want to reraise. We
            # only care about the first exception on the queue -- it was the first caught exception so it "wins".
            if not self._handled_exceptions.empty():
                handled_exception = self._handled_exceptions.get()

                # We reraise SystemExit on the main thread -- this specific exception is how Python controls setting
                # the process exit code, and that only works if raised on the main thread.
                if isinstance(handled_exception, SystemExit):
                    raise handled_exception

                # We also want to make sure the process exit code is set non-zero if the UnhandledExceptionHandler
                # handled any Exception at all. (Note: this does not include AppTeardown or KeyboardInterrupt, which
                # both inherit from BaseException.)
                if isinstance(handled_exception, Exception):
                    raise SystemExit(self.HANDLED_EXCEPTION_EXIT_CODE)

            # If an exception was raised while executing one of the teardown callbacks, also make sure to exit with a
            # non-zero exit code.
            if self._teardown_callback_raised_exception:
                raise SystemExit(self.EXCEPTION_DURING_TEARDOWN_EXIT_CODE)

        # Returning True from this method tells Python not to re-raise the exc_value exception on the current thread.
        return True
Enables this to be used as a context manager. If an exception was raised during the execution block (inside the
dataset/ETHPy150Open box/ClusterRunner/app/util/unhandled_exception_handler.py/UnhandledExceptionHandler.__exit__