gotta impl filter

master
bel 2023-03-25 21:07:14 -06:00
parent 68b6667c76
commit 0f12fbc8c1
1 changed files with 24 additions and 3 deletions

View File

@ -10,11 +10,13 @@ def main():
managerToParserQ = queue.Queue(maxsize=1)
readerToParserQ = queue.Queue(maxsize=10)
parserToReactorQ = queue.Queue(maxsize=10)
reactorToActorQ = queue.Queue(maxsize=10)
threads = [
Manager(managerToParserQ),
Reader(managerToParserQ, readerToParserQ),
Parser(readerToParserQ, parserToReactorQ),
Reactor(parserToReactorQ),
Reactor(parserToReactorQ, reactorToActorQ),
Actor(reactorToActorQ),
]
[t.start() for t in threads]
[t.join() for t in threads]
@ -86,7 +88,7 @@ class Parser(threading.Thread):
clip = self.inq.get()
if not clip:
break
self.outq.put(self._run(clip))
self.outq.put(self._run(clip).strip())
except Exception as e:
log("Parser.run: error:", e)
self.outq.put(None)
@ -98,9 +100,10 @@ class Parser(threading.Thread):
class Reactor(threading.Thread):
def __init__(self, inq):
def __init__(self, inq, outq):
threading.Thread.__init__(self)
self.inq = inq
self.outq = outq
def run(self):
log("Reactor.run: start")
@ -109,10 +112,28 @@ class Reactor(threading.Thread):
if text is None:
break
self.handle(text)
self.outq.put(None)
log("Reactor.run: stop")
def handle(self, text):
print(text)
class Actor(threading.Thread):
def __init__(self, inq):
threading.Thread.__init__(self)
self.inq = inq
def run(self):
log("Actor.run: start")
while True:
hotword = self.inq.get()
if hotword is None:
break
self.handle(hotword)
log("Actor.run: stop")
def handle(self, hotword):
print(hotword)
if __name__ == "__main__":
main()