Fix 300s executor shutdown with threading.Event
Replace time.sleep() with threading.Event.wait() in all poll loops so worker threads exit immediately on shutdown instead of blocking for up to 500ms per iteration. Fixes the on_unmount crash (NoMatches from querying removed DOM nodes) by signaling the event directly rather than iterating child widgets. Three shutdown paths covered: q key (on_unmount), Ctrl+C (try/finally in main), and Textual internal shutdown.
This commit is contained in:
parent
48746937a7
commit
ba8859cc31
4 changed files with 23 additions and 19 deletions
|
|
@ -7,7 +7,6 @@ raw (az, el, rssi) data for offline analysis.
|
|||
|
||||
import csv
|
||||
import logging
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from textual import work
|
||||
|
|
@ -98,6 +97,7 @@ class ScanScreen(Container):
|
|||
def _do_scan(self) -> None:
|
||||
"""Execute the AZ/EL grid scan in a background thread."""
|
||||
worker = get_current_worker()
|
||||
shutdown = self.app.shutdown_event
|
||||
device = self._device
|
||||
if device is None:
|
||||
return
|
||||
|
|
@ -146,7 +146,7 @@ class ScanScreen(Container):
|
|||
|
||||
for _el_idx, el_val in enumerate(el_values):
|
||||
for _az_idx, az_val in enumerate(az_values):
|
||||
if not self._scanning or worker.is_cancelled:
|
||||
if not self._scanning or worker.is_cancelled or shutdown.is_set():
|
||||
self.app.call_from_thread(self._set_status, "Scan stopped")
|
||||
return
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ class ScanScreen(Container):
|
|||
continue
|
||||
|
||||
# Settle time -- let the motor stop and vibrations damp.
|
||||
time.sleep(0.3)
|
||||
shutdown.wait(0.3)
|
||||
|
||||
# Read signal.
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue