فهرست منبع

#15 drop the interrupted flag from input sources

Martin 10 سال پیش
والد
کامیت
41e01a39b3

+ 3 - 2
voice_control/input_sources/__init__.py

@@ -21,16 +21,17 @@ class TokenStream(object):
     def get_line(self, timeout):
         return self.get_token(timeout)
 
-def launch_input_sources(interrupted):
+def launch_input_sources():
     global _TOKEN_STREAM
     _TOKEN_STREAM = TokenStream()
 
     services = [
-        console_input.ConsoleInput(_TOKEN_STREAM, interrupted)
+        console_input.ConsoleInput(_TOKEN_STREAM)
     ]
 
     for s in services:
         t = threading.Thread(target=s.run)
+        t.setDaemon(True)
         t.start()
 
 def get_token(timeout=120, preferred_phrases=None):

+ 2 - 3
voice_control/input_sources/console_input.py

@@ -1,10 +1,9 @@
 class ConsoleInput(object):
-    def __init__(self, token_stream, interrupted):
+    def __init__(self, token_stream):
         self.stream = token_stream
-        self.interrupted = interrupted
     
     def run(self):
-        while not self.interrupted():
+        while True:
             try:
                 cmd = raw_input('> ')
                 for token in cmd.split(' '):

+ 1 - 1
voice_control/main.py

@@ -21,7 +21,7 @@ def _init_logging():
 
 if __name__ == "__main__":
     _init_logging()
-    input_sources.launch_input_sources(_interrupt_callback)
+    input_sources.launch_input_sources()
     services.launch_services(_interrupt_callback)
 
     #init_all(_AUDIO_SERVICES[0]['callbacks'].values())

+ 2 - 0
voice_control/services/__init__.py

@@ -27,5 +27,7 @@ def launch_services(interrupted):
         if t is not None and t in services and services[t].initialized:
             output.debug('Entering %s' % t)
             services[t].call()
+        elif t == 'quit':
+            return
         elif t is not None:
             output.failure('"%s" is not a valid service.' % t)