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:
parent
83c1f79caf
commit
48746937a7
@ -129,6 +129,17 @@ class BirdcageApp(App):
|
|||||||
if hasattr(screen, "on_show"):
|
if hasattr(screen, "on_show"):
|
||||||
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:
|
def action_toggle_dark(self) -> None:
|
||||||
self.dark = not self.dark
|
self.dark = not self.dark
|
||||||
|
|
||||||
|
|||||||
@ -87,6 +87,10 @@ class PositionScreen(Container):
|
|||||||
self._polling = True
|
self._polling = True
|
||||||
self._poll_worker = self._do_position_poll()
|
self._poll_worker = self._do_position_poll()
|
||||||
|
|
||||||
|
def on_unmount(self) -> None:
|
||||||
|
"""Stop polling thread on teardown."""
|
||||||
|
self._polling = False
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Position poll worker
|
# Position poll worker
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|||||||
@ -71,6 +71,10 @@ class SignalScreen(Container):
|
|||||||
"""Called when this screen becomes visible."""
|
"""Called when this screen becomes visible."""
|
||||||
pass # Monitoring is explicit via Start/Stop buttons.
|
pass # Monitoring is explicit via Start/Stop buttons.
|
||||||
|
|
||||||
|
def on_unmount(self) -> None:
|
||||||
|
"""Stop monitoring thread on teardown."""
|
||||||
|
self._monitoring = False
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Signal poll worker
|
# Signal poll worker
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user