some fixes
This commit is contained in:
@@ -15,6 +15,17 @@ from python_app.hardware_full.librevna_multi_device_driver.protocol import Packe
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# The sweep free-runs by design, so devices stream datapoints continuously even
|
||||
# while no acquisition is consuming them (e.g. an operator pausing between manual
|
||||
# combo captures). An unbounded queue then grows without limit — hundreds of MB
|
||||
# over a few minutes — and the next acquisition's drain spends seconds discarding
|
||||
# the backlog on the GUI thread. Bound the queue and drop the OLDEST packet on
|
||||
# overflow: every acquisition drains stale packets before collecting anyway, and
|
||||
# whenever packets actually matter (ACK waits, cycle collection) a consumer is
|
||||
# already pulling, so the queue never approaches the bound. Sized to hold many
|
||||
# full sweeps of datapoints with a wide margin.
|
||||
_RECEIVED_PACKET_QUEUE_MAX = 32768
|
||||
|
||||
|
||||
class LibreVnaUsbBulkConnection:
|
||||
"""Minimal packet transport for one LibreVNA device."""
|
||||
@@ -29,7 +40,9 @@ class LibreVnaUsbBulkConnection:
|
||||
raise ValueError("serial_number is required for multi-device acquisition")
|
||||
self.serial_number = serial_number
|
||||
self._scanner = FrameScanner()
|
||||
self._received_packets: queue.Queue[tuple[int, bytes]] = queue.Queue()
|
||||
self._received_packets: queue.Queue[tuple[int, bytes]] = queue.Queue(
|
||||
maxsize=_RECEIVED_PACKET_QUEUE_MAX
|
||||
)
|
||||
self._fatal_error: Exception | None = None
|
||||
self._fatal_lock = threading.Lock()
|
||||
self._transport = USBTransport(
|
||||
@@ -108,7 +121,20 @@ class LibreVnaUsbBulkConnection:
|
||||
logger.warning("Dropping unparseable USB chunk from %s: %s", self.serial_number, exc)
|
||||
return
|
||||
for packet in packets:
|
||||
self._received_packets.put((int(packet.type), bytes(packet.payload)))
|
||||
entry = (int(packet.type), bytes(packet.payload))
|
||||
while True:
|
||||
try:
|
||||
self._received_packets.put_nowait(entry)
|
||||
break
|
||||
except queue.Full:
|
||||
# Blocking here would stall the USB read thread; discard the
|
||||
# oldest packet instead — stale data is what the pre-collect
|
||||
# drain throws away anyway. Racing a concurrent consumer just
|
||||
# means the queue already has room again.
|
||||
try:
|
||||
self._received_packets.get_nowait()
|
||||
except queue.Empty:
|
||||
pass
|
||||
|
||||
def _on_disconnect(self, exc: Exception) -> None:
|
||||
"""Record an asynchronous transport disconnect as the fatal error."""
|
||||
|
||||
Reference in New Issue
Block a user