Пример #1
0
 def _repr_pretty_(self, p, cycle):
     # used by IPython
     from easypy.colors import BLUE
     if cycle:
         p.text('DataSize(...)')
         return
     p.text(BLUE(self))
Пример #2
0
    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)