fix(B6): cancel_pending thread-safe via threading.Event

This commit is contained in:
Bernd (Hermes)
2026-07-24 17:08:05 +02:00
parent 324e7cd491
commit 9db62bf94a
2 changed files with 8 additions and 7 deletions
+6 -5
View File
@@ -654,7 +654,7 @@ class PulseController:
self._phase: bool = False # False=online, True=away
self._last_sent_phase: Optional[bool] = None
self._background_count: int = 0
self._cancel_pending: bool = False # P0-2: skip next tick flag
self._cancel_pending_event = threading.Event() # B6: thread-safe via Event statt bool
# P1-2 O-2: Async-await bridge
self._loop: Optional[asyncio.AbstractEventLoop] = None
self._await_timeout: float = 2.0
@@ -765,7 +765,7 @@ class PulseController:
status fires while the PulseController is running.
Sets a flag that the next tick will skip.
"""
self._cancel_pending = True
self._cancel_pending_event.set()
logger.debug("[pulse] cancel_pending: next tick will be skipped")
# ── Internal: Pulse Loop ─────────────────────────────────────────────
@@ -814,13 +814,14 @@ class PulseController:
self._phase,
self._ddp is not None,
self._paused.is_set(),
self._cancel_pending,
self._cancel_pending_event.is_set(),
self._loop is not None,
)
# P0-2: Check cancel_pending flag (set by PresenceEngine._set_presence)
if self._cancel_pending:
self._cancel_pending = False
# B6: thread-safe via threading.Event statt bool
if self._cancel_pending_event.is_set():
self._cancel_pending_event.clear()
logger.debug("[pulse] _pulse_tick skip: cancel_pending was set")
return