:param types.TracebackType|types.FrameType|StackSummary tb:
    :param io.TextIOBase|io.StringIO|None file: stderr by default
    :return: nothing, prints to ``file``
966264
def print_tb(tb, file=None, **kwargs):
    
    if file is None:
        file = sys.stderr
    for l in format_tb(tb=tb, **kwargs):
        file.write(l)
    file.flush()
408407
def excepthook(excType, excValue, tracebackobj):
    
    separator = '-' * 80

    logFile = os.path.join(tempfile.gettempdir(), "error.log")

    notice = "An unhandled exception occurred. Please report the problem.\n"

    notice += """A log has been written to "{}".\n\nError information:""".format(logFile)

    timeString = time.strftime("%Y-%m-%d, %H:%M:%S")

    tbinfofile = io.StringIO()
    traceback.print_tb(tracebackobj, None, tbinfofile)
    tbinfofile.seek(0)
    tbinfo = tbinfofile.read()
    if python_version < 3:
        # Python3 has no str().decode()
        tbinfo = tbinfo.decode('utf-8')
    else:
        pass

    try:
        if python_version < 3:
            # Python3 has no str().decode()
            excValueStr = str(excValue).decode('utf-8')
        else:
            excValueStr = str(excValue)

    except UnicodeEncodeError:
        excValueStr = str(excValue)

    errmsg = '{0}: \n{1}'.format(excType, excValueStr)

    sections = ['\n', separator, timeString, separator,
                errmsg, separator, tbinfo]
    try:
        msg = '\n'.join(sections)

    except TypeError:
        # Remove all things not string.
        sections = [item for item in sections if type(item) == str]
        msg = '\n'.join(sections)

    try:
        f = codecs.open(logFile, "a+", encoding='utf-8')
        f.write(msg)
        f.close()
    except IOError:
        msgbox("unable to write to {0}".format(logFile), "Writing error")

    # always show an error message
    try:
        if not _isQAppRunning():
            app = QtGui.QApplication([])
        _showMessageBox(str(notice) + str(msg))
    except Exception:
        msgbox(str(notice) + str(msg), "Error")
327627
def _scons_user_error(e):
    
    global print_stacktrace
    etype, value, tb = sys.exc_info()
    if print_stacktrace:
        traceback.print_exception(etype, value, tb)
    filename, lineno, routine, dummy = find_deepest_user_frame(traceback.extract_tb(tb))
    sys.stderr.write("\nscons: *** %s\n" % value)
    sys.stderr.write('File "%s", line %d, in %s\n' % (filename, lineno, routine))
    sys.exit(2)
1176874
def error(self, msg):
        """"""
        print("***", msg, file=self.stdout)

        if not self.config.show_traceback_on_error:
            return

        etype, evalue, tb = sys.exc_info()
        if tb and tb.tb_frame.f_code.co_name == "default":
            tb = tb.tb_next
            if tb and tb.tb_frame.f_code.co_filename == "<stdin>":
                tb = tb.tb_next
                if tb:  # only display with actual traceback.
                    self._remove_bdb_context(evalue)
                    tb_limit = self.config.show_traceback_on_error_limit
                    fmt_exc = traceback.format_exception(
                        etype, evalue, tb, limit=tb_limit
                    )

                    # Remove last line (exception string again).
                    if len(fmt_exc) > 1 and fmt_exc[-1][0] != " ":
                        fmt_exc.pop()

                    print("".join(fmt_exc).rstrip(), file=self.stdout)
908979
def print_error(self, error):
        
        print(colored(error.message, 'red'), file=self.stderr)

        if error.stdout or error.stderr:
            print(file=self.stderr)
            print("Here's what git said:", file=self.stderr)
            print(file=self.stderr)

            if error.stdout:
                print(error.stdout, file=self.stderr)
            if error.stderr:
                print(error.stderr, file=self.stderr)

        if error.details:
            print(file=self.stderr)
            print("Here's what we know:", file=self.stderr)
            print(str(error.details), file=self.stderr)
            print(file=self.stderr)
438835
def log_fault_info_str (exc_info, message = "", level = logging.CRITICAL,
                        traceback = False):
  
  tb = sys.exc_info ()[2]
  stack = _get_stack (tb)
  rc = StringIO ()
  rc.write ("%s: FAULT: %s%s(%s): %s\n"
            % (logging.getLevelName (level),
               ("%s -- " % message) if message else "",
               tb.tb_frame.f_code.co_filename,
               tb.tb_lineno,
               repr (exc_info[1])))
  if traceback:
    for line in _generate_stackdump (stack):
      rc.write ("%s\n" % line)
  return rc.getvalue ()
1212171
def _short_traceback(skip=3):
  """"""
  counter, res = 0, []
  # Skipping 3 lines by default: the top (useless) and self-call.
  lines = traceback.format_exc().splitlines()[skip:]
  for l in lines:
    res.append(_shorten_file_path(l))
    if counter % 2 == 1:
      res.append('')
    counter += 1
    # If we see a LayerError, the traceback has already been processed.
    if l.startswith('LayerError'):
      # Skip 4 back except last as these are internal base-layer calls.
      res = res[:-4] + [res[-1]]
      res += lines[counter:]
      break
  return '\n'.join(res)
379630
def exception_logging(exctype, value, tb):
    
    write_val = {'exception_type': str(exctype),
                 'message': str(traceback.format_tb(tb, 10))}
    logging.exception(str(write_val))
78685
def _get_traceback_no_io():
    
    try:
        module = load_module(str("_traceback_no_io"), traceback)
    except NotImplementedError:
        # Can't fix the I/O problem, oh well:
        return traceback

    class FakeLineCache(object):
        def checkcache(self, *args, **kwargs):
            None

        def getline(self, *args, **kwargs):
            return ""

        def lazycache(self, *args, **kwargs):
            return None

    module.linecache = FakeLineCache()
    return module
209346
def showtraceback(self, *args, **kwargs):
        """"""
        # Override for avoid using sys.excepthook PY-12600
        try:
            type, value, tb = sys.exc_info()
            sys.last_type = type
            sys.last_value = value
            sys.last_traceback = tb
            tblist = traceback.extract_tb(tb)
            del tblist[:1]
            lines = traceback.format_list(tblist)
            if lines:
                lines.insert(0, "Traceback (most recent call last):\n")
            lines.extend(traceback.format_exception_only(type, value))
        finally:
            tblist = tb = None
        sys.stderr.write(''.join(lines))
961861
def warn_with_traceback(message, category, filename, lineno, file=None, line=None):
    
    import traceback
    traceback.print_stack()
    log = file if hasattr(file, 'write') else sys.stderr
    settings.write(warnings.formatwarning(message, category, filename, lineno, line))
461561
def print_err(*args, **kwargs):
    
    if kwargs.get('file', None) is None:
        kwargs['file'] = sys.stderr
    print(*args, **kwargs)
239880
def print_traceback(self):
        
        traceback.print_exception(self.etype, self.value, self.traceback)
765181
def iter_traceback_frames(tb):
    
    # Some versions of celery have hacked traceback objects that might
    # miss tb_frame.
    while tb and hasattr(tb, 'tb_frame'):
        # support for __traceback_hide__ which is used by a few libraries
        # to hide internal frames.
        f_locals = getattr(tb.tb_frame, 'f_locals', {})
        if not _getitem_from_frame(f_locals, '__traceback_hide__'):
            yield tb.tb_frame, getattr(tb, 'tb_lineno', None)
        tb = tb.tb_next
345820
def _get_stdout_stderr_streams(self):
        """"""
        if six.PY2 or not hasattr(sys.stdout, "buffer"):
            if hasattr(sys.stdout, "fileno") and sys.stdout.isatty():
                try:
                    stdout = os.fdopen(sys.stdout.fileno(), "w+", 0)
                    stderr = os.fdopen(sys.stderr.fileno(), "w+", 0)
                # OSError [Errno 22] Invalid argument wandb
                except OSError:
                    stdout = sys.stdout
                    stderr = sys.stderr
            else:
                stdout = sys.stdout
                stderr = sys.stderr
        else:  # we write binary so grab the raw I/O objects in python 3
            try:
                stdout = sys.stdout.buffer.raw
                stderr = sys.stderr.buffer.raw
            except AttributeError:
                # The testing environment and potentially others may have screwed with their
                # io so we fallback to raw stdout / err
                stdout = sys.stdout.buffer
                stderr = sys.stderr.buffer

        output_log_path = os.path.join(self._run.dir, OUTPUT_FNAME)
        self._output_log = WriteSerializingFile(open(output_log_path, 'wb'))

        stdout_streams = [stdout, self._output_log]
        stderr_streams = [stderr, self._output_log]

        if self._cloud:
            # Tee stdout/stderr into our TextOutputStream, which will push lines to the cloud.
            fs_api = self._api.get_file_stream_api()
            self._stdout_stream = streaming_log.TextStreamPusher(
                fs_api, OUTPUT_FNAME, prepend_timestamp=True)
            self._stderr_stream = streaming_log.TextStreamPusher(
                fs_api, OUTPUT_FNAME, line_prepend='ERROR',
                prepend_timestamp=True)

            stdout_streams.append(self._stdout_stream)
            stderr_streams.append(self._stderr_stream)

        return stdout_streams, stderr_streams
1122043
def _print_errs(self):
        
        i = 0
        for error in self.errors:
            print(self._errmsg(error, tb=True, i=i))
            # for spacing
            if self.errs_traceback is False:
                print()
            i += 1
254430
def get_traceback_stxt():
        
        #/
        exc_cls, exc_obj, tb_obj = sys.exc_info()
        
        #/
        txt_s = traceback.format_exception(exc_cls, exc_obj, tb_obj)
    
        #/
        res = ''.join(txt_s)
    
        return res