some fixes
This commit is contained in:
@@ -86,12 +86,23 @@ class ControlButtonWatcher(QObject):
|
||||
|
||||
def start(self) -> None:
|
||||
"""Open the GPIO line and begin watching for presses on a background thread."""
|
||||
self._line.open()
|
||||
self._stop_read_fd, self._stop_write_fd = os.pipe()
|
||||
self._thread = threading.Thread(
|
||||
target=self._run, name="control-button-watcher", daemon=True
|
||||
)
|
||||
self._thread.start()
|
||||
# Guard against double-start: a second start would leak the first line/pipe/thread.
|
||||
if self._thread is not None:
|
||||
return
|
||||
try:
|
||||
self._line.open()
|
||||
self._stop_read_fd, self._stop_write_fd = os.pipe()
|
||||
self._thread = threading.Thread(
|
||||
target=self._run, name="control-button-watcher", daemon=True
|
||||
)
|
||||
self._thread.start()
|
||||
except Exception:
|
||||
# Release any line/pipe fds opened before the failure so nothing leaks
|
||||
# and no orphaned thread survives a partial start.
|
||||
self._thread = None
|
||||
self._close_stop_pipe()
|
||||
self._line.close()
|
||||
raise
|
||||
|
||||
def stop(self) -> None:
|
||||
"""Signal the watcher thread to exit and release the GPIO line and pipe."""
|
||||
|
||||
Reference in New Issue
Block a user