From: Jannis Harder Date: Wed, 13 Jul 2022 13:54:24 +0000 (+0200) Subject: Fix a race-condition SbyProc that could truncate output X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5d3f784bebd7f952ccfbe8323f6d97b66f2ebf04;p=SymbiYosys.git Fix a race-condition SbyProc that could truncate output Present for a long time, but was not easy to hit. Some of my work in progress changes made this much more likely and running the complete test suite in parallel had a good chance of reproducing this for at least one of the tests. --- diff --git a/sbysrc/sby_core.py b/sbysrc/sby_core.py index 372cbeb..391fb16 100644 --- a/sbysrc/sby_core.py +++ b/sbysrc/sby_core.py @@ -183,17 +183,12 @@ class SbyProc: self.running = True return - while True: - outs = self.p.stdout.readline().decode("utf-8") - if len(outs) == 0: break - if outs[-1] != '\n': - self.linebuffer += outs - break - outs = (self.linebuffer + outs).strip() - self.linebuffer = "" - self.handle_output(outs) + self.read_output() if self.p.poll() is not None: + # The process might have written something since the last time we checked + self.read_output() + if not self.silent: self.task.log(f"{self.info}: finished (returncode={self.p.returncode})") self.task.update_proc_stopped(self) @@ -231,6 +226,17 @@ class SbyProc: next_proc.poll() return + def read_output(self): + while True: + outs = self.p.stdout.readline().decode("utf-8") + if len(outs) == 0: break + if outs[-1] != '\n': + self.linebuffer += outs + break + outs = (self.linebuffer + outs).strip() + self.linebuffer = "" + self.handle_output(outs) + class SbyAbort(BaseException): pass