MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / _SpinnerThread

Class _SpinnerThread

misc/python/materialize/parallel_task.py:89–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87
88
89class _SpinnerThread(threading.Thread):
90 def __init__(self, remaining: int, suffix: str = "tasks") -> None:
91 super().__init__(daemon=True)
92 self._remaining = remaining
93 self._suffix = suffix
94 # "checks in foo" -> "check in foo"
95 parts = suffix.split(" ", 1)
96 self._singular = parts[0].rstrip("s") + (
97 " " + parts[1] if len(parts) > 1 else ""
98 )
99 self._lock = threading.Lock()
100 self.active = not buildkite.is_in_buildkite() and sys.stdout.isatty()
101
102 def run(self) -> None:
103 symbols = ["⣾", "⣷", "⣯", "⣟", "⡿", "⢿", "⣻", "⣽"]
104 i = 0
105 while self.active:
106 with self._lock:
107 remaining = self._remaining
108 suffix = self._suffix if remaining != 1 else self._singular
109 print(
110 f"\r\033[K{symbols[i]} {remaining} {suffix}",
111 end="",
112 flush=True,
113 )
114 i = (i + 1) % len(symbols)
115 time.sleep(0.1)
116
117 def task_done(self) -> None:
118 with self._lock:
119 self._remaining -= 1
120
121 def clear_line(self) -> None:
122 if self.active:
123 print("\r\033[K", end="", flush=True)
124
125 def stop(self) -> None:
126 if self.active:
127 self.active = False
128 print("\r\033[K", end="", flush=True)
129
130
131def run_parallel(

Callers 1

run_parallelFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected