Merge pull request #1956 from MycroftAI/feature/threaded-common-query

Run common query skill queries in threads
pull/1957/head
Åke 2019-01-17 12:38:12 +01:00 committed by GitHub
commit 06f9d2f4db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -16,6 +16,7 @@ from enum import IntEnum
from abc import ABC, abstractmethod
from mycroft import MycroftSkill
from mycroft.messagebus.message import Message
from multiprocessing.pool import ThreadPool
class CQSMatchLevel(IntEnum):
@ -41,6 +42,8 @@ def handles_visuals(self, platform):
class CommonQuerySkill(MycroftSkill, ABC):
pool = ThreadPool(5)
def __init__(self, name=None, bus=None):
super().__init__(name, bus)
@ -51,6 +54,10 @@ class CommonQuerySkill(MycroftSkill, ABC):
self.add_event('question:action', self.__handle_query_action)
def __handle_question_query(self, message):
CommonQuerySkill.pool.apply_async(self.__thread_question_query,
args=[message])
def __thread_question_query(self, message):
search_phrase = message.data["phrase"]
# First, notify the requestor that we are attempting to handle