Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2529 from forslund/feature/stop-sequence
Browse files Browse the repository at this point in the history
Update skill stop sequence
  • Loading branch information
forslund authored Apr 7, 2020
2 parents 0e15688 + 9246190 commit fb35687
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mycroft/skills/audioservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def track_info(self):
info = self.bus.wait_for_response(
Message('mycroft.audio.service.track_info'),
reply_type='mycroft.audio.service.track_info_reply',
timeout=5)
timeout=1)
return info.data if info else {}

def available_backends(self):
Expand Down
42 changes: 34 additions & 8 deletions mycroft/skills/skill_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os
from glob import glob
from threading import Thread, Event, Lock
from time import sleep, time
from time import sleep, time, monotonic

from mycroft.api import is_paired
from mycroft.enclosure.api import EnclosureAPI
Expand Down Expand Up @@ -51,6 +51,10 @@ def start(self):
self.send()
self.started = True

def stop(self):
"""Stop the queue, and hinder any further transmissions."""
self.started = False

def send(self):
"""Loop through all stored loaders triggering settingsmeta upload."""
with self.lock:
Expand All @@ -59,7 +63,10 @@ def send(self):
if queue:
LOG.info('New Settings meta to upload.')
for loader in queue:
loader.instance.settings_meta.upload()
if self.started:
loader.instance.settings_meta.upload()
else:
break

def __len__(self):
return len(self._queue)
Expand All @@ -77,6 +84,29 @@ def put(self, loader):
self._queue.append(loader)


def _shutdown_skill(instance):
"""Shutdown a skill.
Call the default_shutdown method of the skill, will produce a warning if
the shutdown process takes longer than 1 second.
Arguments:
instance (MycroftSkill): Skill instance to shutdown
"""
try:
ref_time = monotonic()
# Perform the shutdown
instance.default_shutdown()

shutdown_time = monotonic() - ref_time
if shutdown_time > 1:
LOG.warning('{} shutdown took {} seconds'.format(instance.skill_id,
shutdown_time))
except Exception:
LOG.exception('Failed to shut down skill: '
'{}'.format(instance.skill_id))


class SkillManager(Thread):
_msm = None

Expand Down Expand Up @@ -378,16 +408,12 @@ def stop(self):
"""Tell the manager to shutdown."""
self._stop_event.set()
self.settings_downloader.stop_downloading()
self.upload_queue.stop()

# Do a clean shutdown of all skills
for skill_loader in self.skill_loaders.values():
if skill_loader.instance is not None:
try:
skill_loader.instance.default_shutdown()
except Exception:
LOG.exception(
'Failed to shut down skill: ' + skill_loader.skill_id
)
_shutdown_skill(skill_loader.instance)

def handle_converse_request(self, message):
"""Check if the targeted skill id can handle conversation
Expand Down
2 changes: 1 addition & 1 deletion stop-mycroft.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ case ${OPT} in
;&
"")
echo "Stopping all mycroft-core services"
end-process messagebus.service
end-process skills
end-process audio
end-process speech
end-process enclosure
end-process messagebus.service
;;
"bus")
end-process messagebus.service
Expand Down

0 comments on commit fb35687

Please sign in to comment.