Skip to content

Commit bd920ab

Browse files
committed
lock output
1 parent 29f777d commit bd920ab

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

bin/fuzz.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import generate
55
import shutil
66
import signal
7+
import sys
78
import time
89
import threading
910
from colorama import Style
1011
from pathlib import Path
11-
from typing import Any, Optional
12+
from typing import Any, Optional, TextIO
1213

1314
import parallel
1415
from util import *
@@ -172,6 +173,23 @@ def _run(self, bar: ProgressBar) -> None:
172173
localbar.done()
173174

174175

176+
class FuzzProgressBar(ProgressBar):
177+
def __init__(self, queue: parallel.AbstractQueue, prefix: str, max_len: int):
178+
super().__init__(prefix, max_len)
179+
self.queue = queue
180+
181+
def _print(
182+
self,
183+
*objects,
184+
sep: str = "",
185+
end: str = "\n",
186+
file: TextIO = sys.stderr,
187+
flush: bool = True,
188+
):
189+
self.queue.ensure_alive()
190+
super()._print(*objects, sep=sep, end=end, file=file, flush=flush)
191+
192+
175193
class Fuzz:
176194
def __init__(self, problem: problem.Problem):
177195
self.generators_yaml_mutex = threading.Lock()
@@ -256,15 +274,15 @@ def runner(task: GeneratorTask | SubmissionTask) -> None:
256274
],
257275
)
258276
max_len += len(f"{self.tmp_ids}: ")
259-
bar = ProgressBar("Fuzz", max_len=max_len)
277+
bar = FuzzProgressBar(self.queue, "Fuzz", max_len=max_len)
260278

261279
def soft_exit(sig: Any, frame: Any) -> None:
262280
if self.queue.aborted:
263281
fatal("Running interrupted", force=True)
264282
else:
265283
self.queue.abort()
266284
with bar:
267-
bar.clearline()
285+
print(bar.carriage_return, file=sys.stderr)
268286
message(
269287
"Running interrupted (waiting on remaining tasks)\n",
270288
"\nFuzz",

0 commit comments

Comments
 (0)