From 4f2a5f17a28832822e99d9c2564b30988796bd96 Mon Sep 17 00:00:00 2001 From: christian Date: Sun, 18 Oct 2026 05:59:30 -0400 Subject: [PATCH] Remote MIDI reader restarts after a minute of an empty session list; one temp file per JSON writer A reader that reconnects while the other Mac is still at the login window never sees the user's MIDI sessions and reports none for ever (four false NO SESSION alarms after the Tracks and ProPresenter Macs rebooted on Sunday morning). Two threads writing fixes-running.json shared one temp file and one rename failed. Co-Authored-By: Claude Fable 5.1 --- status_panel.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/status_panel.py b/status_panel.py index 119309d..16b4fe5 100644 --- a/status_panel.py +++ b/status_panel.py @@ -845,7 +845,7 @@ def check_identity(chk): def write_json(path, obj): """Write a small JSON file in one go (a reader never sees half of it).""" - tmp = path + ".tmp" + tmp = "%s.%d-%x.tmp" % (path, os.getpid(), threading.get_ident() & 0xFFFF) # one per writer: two threads never trip over one file with open(tmp, "w") as f: json.dump(obj, f, indent=1, sort_keys=True) os.replace(tmp, path) @@ -2290,11 +2290,21 @@ def stream_remote_midi(snap, cfg, host, stop): stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True) proc.stdin.write(script) proc.stdin.close() + empty_since = None for line in proc.stdout: data = parse_remote_midi(line) if data is not None: snap.remote_midi[host], snap.remote_midi_time[host] = data, time.time() remember_peers(snap, host, data) + # A reader started while that Mac was still at the login window never sees the + # user's MIDI sessions: it reports none, for ever. Start again after a minute of nothing. + if data == {}: + empty_since = empty_since or time.time() + if time.time() - empty_since > 60: + log.info("MIDI stream from %s reports no sessions for a minute: reconnecting", host) + break + else: + empty_since = None if stop.is_set(): break except (OSError, ValueError) as e: