Fix executor shutdown warning on TUI exit

Poll threads (position at 2 Hz, signal when monitoring) run
while-loops with time.sleep() that never exit on app quit.
Add on_unmount() to PositionScreen, SignalScreen, and BirdcageApp
to clear polling flags and disconnect the device, so worker threads
exit within the sleep interval instead of hitting the 300s timeout.
This commit is contained in:
Ryan Malloy 2026-02-14 09:41:47 -07:00
parent 83c1f79caf
commit 48746937a7
3 changed files with 19 additions and 0 deletions

View File

@ -129,6 +129,17 @@ class BirdcageApp(App):
if hasattr(screen, "on_show"):
screen.on_show()
def on_unmount(self) -> None:
"""Stop all polling threads and disconnect the device on shutdown."""
for mode_key in MODES:
screen = self.query_one(f"#{mode_key}")
if hasattr(screen, "_polling"):
screen._polling = False
if hasattr(screen, "_monitoring"):
screen._monitoring = False
if self.device and hasattr(self.device, "disconnect"):
self.device.disconnect()
def action_toggle_dark(self) -> None:
self.dark = not self.dark

View File

@ -87,6 +87,10 @@ class PositionScreen(Container):
self._polling = True
self._poll_worker = self._do_position_poll()
def on_unmount(self) -> None:
"""Stop polling thread on teardown."""
self._polling = False
# ------------------------------------------------------------------
# Position poll worker
# ------------------------------------------------------------------

View File

@ -71,6 +71,10 @@ class SignalScreen(Container):
"""Called when this screen becomes visible."""
pass # Monitoring is explicit via Start/Stop buttons.
def on_unmount(self) -> None:
"""Stop monitoring thread on teardown."""
self._monitoring = False
# ------------------------------------------------------------------
# Signal poll worker
# ------------------------------------------------------------------