fix(B6): cancel_pending thread-safe via threading.Event
This commit is contained in:
@@ -654,7 +654,7 @@ class PulseController:
|
|||||||
self._phase: bool = False # False=online, True=away
|
self._phase: bool = False # False=online, True=away
|
||||||
self._last_sent_phase: Optional[bool] = None
|
self._last_sent_phase: Optional[bool] = None
|
||||||
self._background_count: int = 0
|
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
|
# P1-2 O-2: Async-await bridge
|
||||||
self._loop: Optional[asyncio.AbstractEventLoop] = None
|
self._loop: Optional[asyncio.AbstractEventLoop] = None
|
||||||
self._await_timeout: float = 2.0
|
self._await_timeout: float = 2.0
|
||||||
@@ -765,7 +765,7 @@ class PulseController:
|
|||||||
status fires while the PulseController is running.
|
status fires while the PulseController is running.
|
||||||
Sets a flag that the next tick will skip.
|
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")
|
logger.debug("[pulse] cancel_pending: next tick will be skipped")
|
||||||
|
|
||||||
# ── Internal: Pulse Loop ─────────────────────────────────────────────
|
# ── Internal: Pulse Loop ─────────────────────────────────────────────
|
||||||
@@ -814,13 +814,14 @@ class PulseController:
|
|||||||
self._phase,
|
self._phase,
|
||||||
self._ddp is not None,
|
self._ddp is not None,
|
||||||
self._paused.is_set(),
|
self._paused.is_set(),
|
||||||
self._cancel_pending,
|
self._cancel_pending_event.is_set(),
|
||||||
self._loop is not None,
|
self._loop is not None,
|
||||||
)
|
)
|
||||||
|
|
||||||
# P0-2: Check cancel_pending flag (set by PresenceEngine._set_presence)
|
# P0-2: Check cancel_pending flag (set by PresenceEngine._set_presence)
|
||||||
if self._cancel_pending:
|
# B6: thread-safe via threading.Event statt bool
|
||||||
self._cancel_pending = False
|
if self._cancel_pending_event.is_set():
|
||||||
|
self._cancel_pending_event.clear()
|
||||||
logger.debug("[pulse] _pulse_tick skip: cancel_pending was set")
|
logger.debug("[pulse] _pulse_tick skip: cancel_pending was set")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -413,7 +413,7 @@ class TestPulseControllerPauseInAsyncMode:
|
|||||||
|
|
||||||
# Setze cancel_pending
|
# Setze cancel_pending
|
||||||
pc.cancel_pending()
|
pc.cancel_pending()
|
||||||
assert pc._cancel_pending is True
|
assert pc._cancel_pending_event.is_set()
|
||||||
|
|
||||||
# _pulse_tick sollte übersprungen werden
|
# _pulse_tick sollte übersprungen werden
|
||||||
pc._pulse_tick()
|
pc._pulse_tick()
|
||||||
@@ -421,7 +421,7 @@ class TestPulseControllerPauseInAsyncMode:
|
|||||||
# set_status sollte NICHT aufgerufen worden sein
|
# set_status sollte NICHT aufgerufen worden sein
|
||||||
mock_ddp.set_status.assert_not_called()
|
mock_ddp.set_status.assert_not_called()
|
||||||
# cancel_pending sollte zurückgesetzt sein
|
# cancel_pending sollte zurückgesetzt sein
|
||||||
assert pc._cancel_pending is False
|
assert not pc._cancel_pending_event.is_set()
|
||||||
|
|
||||||
|
|
||||||
# ═══════════════════════════════════════════════════════════════════════════
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|||||||
Reference in New Issue
Block a user