Helios panel: refresh about every 0.65 s, and yield the port to the operator
Three things were making the panel feel slow, all of them waiting rather than working. The trailing quiet window is waited out once per query, so it set the pace of the whole sweep: at 50 ms that was 400 ms of a 590 ms poll spent listening to silence. A reply streams at the baud rate — ~1 ms between bytes, no measurable gap between its lines — and the deadline restarts on every line read, so 20 ms outlasts the gap it exists for twenty times over. A tail that still arrives late is caught by _discard_input(), which is what actually protects the next query. Replayed against the rig transcript, a sweep goes from 590 ms to 356 ms. The poll interval was 1 s on top of that, so a value could be 1.6 s stale. At 0.3 s the panel comes round about every 0.65 s. And a poll held the port for its whole sweep, so a button pressed during one waited for all eight queries. _work_pending() on the worker base lets a poll drop what is left as soon as the operator queues something: a click now waits ~135 ms for the register read in progress instead of the full sweep, and the rest is picked up next time round. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -137,6 +137,55 @@ def test_polling_never_overlaps_or_backs_up(qapp):
|
||||
assert queued <= 1, f"{queued} stale polls queued up"
|
||||
|
||||
|
||||
class _YieldingPoller(PollingQueueWorker):
|
||||
"""A poll made of several reads that gives up as soon as work arrives."""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(poll_interval_s=0.02)
|
||||
self.reads = 0
|
||||
self.handled = []
|
||||
self.is_connected = True
|
||||
self._handlers["click"] = self._click
|
||||
|
||||
def _click(self, value):
|
||||
self.handled.append(value)
|
||||
|
||||
def _poll_once(self):
|
||||
for _ in range(6):
|
||||
if self._work_pending():
|
||||
return
|
||||
time.sleep(0.02)
|
||||
self.reads += 1
|
||||
|
||||
|
||||
def test_a_queued_command_interrupts_a_poll(qapp):
|
||||
"""A button pressed mid-poll should not wait out the whole sweep.
|
||||
|
||||
The Helios sweep is eight serial queries; before this, a command queued
|
||||
behind one waited for every last read to finish.
|
||||
"""
|
||||
w = _YieldingPoller()
|
||||
t = threading.Thread(target=w.run, daemon=True)
|
||||
t.start()
|
||||
w.start_polling()
|
||||
time.sleep(0.03) # a poll is now in progress
|
||||
|
||||
pressed = time.monotonic()
|
||||
w._enqueue("click", value="set current")
|
||||
deadline = pressed + 2.0
|
||||
while not w.handled and time.monotonic() < deadline:
|
||||
time.sleep(0.002)
|
||||
waited = time.monotonic() - pressed
|
||||
|
||||
w.stop_polling()
|
||||
w.stop_worker()
|
||||
t.join(timeout=5)
|
||||
|
||||
assert w.handled == ["set current"]
|
||||
# A full sweep is 6 x 20 ms; the command must not have waited for it.
|
||||
assert waited < 0.08, f"command waited {waited * 1000:.0f} ms for the poll"
|
||||
|
||||
|
||||
def test_stop_polling_halts_the_cycle(qapp):
|
||||
w = _Poller()
|
||||
t = threading.Thread(target=w.run, daemon=True)
|
||||
|
||||
Reference in New Issue
Block a user