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: