def error_box(self, *exc, extra=None): if len(exc) == 1: exc, = exc typ = type(exc) tb = None else: typ, exc, tb = exc header = "%s.%s" % (typ.__module__, typ.__name__) self.error("YELLOW@{%s}@ RED@{%s}@", header, LINE * (80 - len(header) - 1), extra=dict(drawing=RED(INDENT_OPEN))) with THREAD_LOGGING_CONTEXT(indentation=1, drawing=RED(INDENT_SEGMENT)): if hasattr(exc, "render") and callable(exc.render): exc_text = exc.render() elif tb: fmt = "DARK_GRAY@{{{}}}@" full_traceback = "".join( traceback.format_exception(typ, exc, tb)) exc_text = "\n".join( map(fmt.format, full_traceback.splitlines())) else: exc_text = str(exc) for line in exc_text.splitlines(): self.error(line) if extra: for line in extra.splitlines(): self.error(line) self.error("RED@{%s}@", DOUBLE_LINE * 80, extra=dict(drawing=RED(INDENT_EXCEPTION)))
def loop(self): wait_seq = cycle(self.WAITING) prog_seq = _progress() wait_symb, progress_symb = map(next, (wait_seq, prog_seq)) last_time = hanging = 0 while True: progressed = self._event.wait(self.SPF) if self._stop: break now = time.time() if now - last_time >= self.SPF: wait_symb = next(wait_seq) last_time = now if progressed: progress_symb = next(prog_seq) hanging = 0 else: hanging += 1 anim = WHITE(wait_symb + progress_symb) elapsed = self._timer.elapsed.render(precision=0).rjust(8) if hanging >= (5 * 10 * 60): # ~5 minutes with no log messages elapsed = RED(elapsed) else: elapsed = BLUE(elapsed) line = elapsed + self._last_line.rstrip() line = line.replace("__PB__", anim) print("\r" + line, end=CLEAR_EOL + "\r", flush=True) self._event.clear() print("\rDone waiting.", end=CLEAR_EOL + "\r", flush=True)