diff --git a/testbench/gui.py b/testbench/gui.py index a63a8bc..5aa2c9a 100644 --- a/testbench/gui.py +++ b/testbench/gui.py @@ -724,6 +724,7 @@ class TestbenchGUI(tk.Tk): self._stop_log() if self.worker: self.worker.stop() + self.worker.join(timeout=5) self.worker = None if self.bench: try: @@ -1130,9 +1131,11 @@ class TestbenchGUI(tk.Tk): "success", ) - # Stop the normal worker so the sweep owns the instruments + # Stop the normal worker and wait for it to finish so the + # sweep thread has exclusive access to the instrument bus if self.worker: self.worker.stop() + self.worker.join(timeout=10) self.worker = None # Restart _poll so it drains the sweep data queue @@ -1190,6 +1193,13 @@ class TestbenchGUI(tk.Tk): elif l_start > l_stop and l_step > 0: l_step = -l_step + # Clear any stale state + time.sleep(0.5) + try: + bench.supply.get_error() + except Exception: + pass + # Sanity check max_v = max(abs(v_start), abs(v_stop)) min_v = min(abs(v_start), abs(v_stop)) @@ -1312,6 +1322,9 @@ class TestbenchGUI(tk.Tk): def _sweep_vi_done(self) -> None: self._btn_svi_run.config(state=tk.NORMAL) self._btn_svi_stop.config(state=tk.DISABLED) + # Wait for sweep thread to fully exit + if self._svi_thread: + self._svi_thread.join(timeout=5) self._svi_thread = None self._svi_stop_event = None # Restart normal worker polling