impl stdout, stderr, and sigusr2 actors
parent
97966a1085
commit
ade19ea36b
|
|
@ -5,6 +5,7 @@ import queue
|
|||
import signal
|
||||
import sys
|
||||
from os import environ
|
||||
from os import kill
|
||||
|
||||
def main():
|
||||
managerToParserQ = queue.Queue(maxsize=1)
|
||||
|
|
@ -169,6 +170,12 @@ class Actor(threading.Thread):
|
|||
def __init__(self, inq):
|
||||
threading.Thread.__init__(self)
|
||||
self.inq = inq
|
||||
self.handle = self.handle_stderr
|
||||
if environ.get("STDOUT", "") == "true":
|
||||
self.handle = self.handle_stdout
|
||||
elif environ.get("SIGUSR2", ""):
|
||||
self.pid = int(environ["SIGUSR2"])
|
||||
self.handle = self.handle_signal
|
||||
|
||||
def run(self):
|
||||
log("Actor.run: start")
|
||||
|
|
@ -179,8 +186,16 @@ class Actor(threading.Thread):
|
|||
self.handle(got[0], got[1])
|
||||
log("Actor.run: stop")
|
||||
|
||||
def handle(self, hotword, context):
|
||||
print(f"'{hotword}' in '{context}'")
|
||||
def handle_stderr(self, hotword, context):
|
||||
log(f"'{hotword}' in '{context}'")
|
||||
|
||||
def handle_stdout(self, hotword, context):
|
||||
log(context)
|
||||
print(hotword)
|
||||
|
||||
def handle_signal(self, hotword, context):
|
||||
self.handle_stderr(hotword, context)
|
||||
kill(self.pid, signal.SIGUSR2)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Reference in New Issue