Change and read a job's steps under one lock.

The worker, the thread that reads the build's output and the window all change a job while the window draws it. A
step could be read with a new state and the value before it, the output's lines could change while they were
copied, and the change counter was incremented without a lock although the window learns from it that the job
ended. Every change and the counter now take the job's lock, and the job screen and the command line copy the steps
under it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-12 22:33:10 -05:00
parent e0870b87b4
commit 3e323d1f94
4 changed files with 141 additions and 48 deletions

View File

@@ -31,12 +31,13 @@ def follow(job):
seen = {}
job.start()
while job.result is None:
for s in job.steps:
key = (s.state, s.value if s.state != jobs.RUNNING else int(s.fraction * 20))
if seen.get(s.id) != key:
seen[s.id] = key
print(f'{s.label}: {s.value}' + (f' ({s.detail})' if s.detail and s.state == jobs.RUNNING else ''),
flush=True)
with job.locked(): # each step as one change of the worker left it
steps = [(s.id, s.label, s.state, s.value, s.fraction, s.detail) for s in job.steps]
for sid, label, state, value, fraction, detail in steps:
key = (state, value if state != jobs.RUNNING else int(fraction * 20))
if seen.get(sid) != key:
seen[sid] = key
print(f'{label}: {value}' + (f' ({detail})' if detail and state == jobs.RUNNING else ''), flush=True)
time.sleep(0.2)
for s in job.steps:
if seen.get(s.id, (None,))[0] != s.state: