diff --git a/ovos_workshop/decorators/killable.py b/ovos_workshop/decorators/killable.py index 871aaf1f..bdb86e3a 100644 --- a/ovos_workshop/decorators/killable.py +++ b/ovos_workshop/decorators/killable.py @@ -41,7 +41,8 @@ def killable_event(msg: str = "mycroft.skills.abort_execution", exc: Type[Exception] = AbortEvent, callback: Optional[callable] = None, react_to_stop: bool = False, call_stop: bool = False, - stop_tts: bool = False): + stop_tts: bool = False, + check_skill_id: bool = False): """ Decorator to mark a method that can be terminated during execution. @param msg: Message name to terminate on @@ -50,6 +51,7 @@ def killable_event(msg: str = "mycroft.skills.abort_execution", @param react_to_stop: If true, also terminate on `stop` Messages @param call_stop: If true, also call `Class.stop` method @param stop_tts: If true, emit message to stop TTS audio playback + @param check_skill_id: If true, require skill_id in message.data to match this skill """ # Begin wrapper def create_killable(func): @@ -68,6 +70,12 @@ def abort(m: Message): if sess.session_id != sess2.session_id: LOG.debug(f"ignoring '{msg}' kill event, event listener not created by this session") return + if check_skill_id: + skill_id = m.data.get("skill_id", "") + if skill_id and skill_id != skill.skill_id: + LOG.debug(f"ignoring '{msg}' kill event, event targeted to {skill_id}") + return + if stop_tts: skill.bus.emit(Message("mycroft.audio.speech.stop")) if call_stop: diff --git a/ovos_workshop/skills/fallback.py b/ovos_workshop/skills/fallback.py index 416e54e0..8001984b 100644 --- a/ovos_workshop/skills/fallback.py +++ b/ovos_workshop/skills/fallback.py @@ -358,12 +358,14 @@ def _handle_fallback_ack(self, message: Message): context={"skill_id": self.skill_id})) def _on_timeout(self): + """_handle_fallback_request timed out and was forcefully killed by ovos-core""" message = dig_for_message() self.bus.emit(message.forward( f"ovos.skills.fallback.{self.skill_id}.killed", data={"error": "timed out"})) - @killable_event("ovos.skills.fallback.force_timeout", callback=_on_timeout) + @killable_event("ovos.skills.fallback.force_timeout", + callback=_on_timeout, check_skill_id=True) def _handle_fallback_request(self, message: Message): """ Handle a fallback request, calling any registered handlers in priority diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index 3ff6477c..a4935050 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -1222,6 +1222,15 @@ def on_deac(message): self.bus.remove("intent.service.skills.deactivate", on_deac) return result + def _on_timeout(self): + """_handle_converse_request timed out and was forcefully killed by ovos-core""" + message = dig_for_message() + self.bus.emit(message.forward( + f"{self.skill_id}.converse.killed", + data={"error": "timed out"})) + + @killable_event("ovos.skills.converse.force_timeout", + callback=_on_timeout, check_skill_id=True) def _handle_converse_request(self, message: Message): """ If this skill is requested and supports converse, handle the user input