diff --git a/fstream-client.py b/fstream-client.py index 5736066..ec3fe94 100644 --- a/fstream-client.py +++ b/fstream-client.py @@ -20,11 +20,24 @@ sp = pUp(s) # script start import subprocess import socket +import threading +import queue bufferSize = 1000 # buffer size in bytes serverAddr = ("127.0.0.1",12000) connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + +class stdoutThread(threading.Thread): + def __init__(self): + threading.Thread.__init__(self) + self.queue = queue.Queue() + + def run(self): + while True: + data = self.queue.get() + sys.stdout.buffer.write(data) + def listToCommand(lst): cmd = "" for arg in lst: @@ -49,10 +62,12 @@ def main(): connection.sendall(makePayload(sys.argv[1:])) if sys.argv[1] == "watch": + stdoutThr = stdoutThread() + stdoutThr.start() while True: data = connection.recv(bufferSize) if data == b"": return - sys.stdout.buffer.write(data) + stdoutThr.queue.put(data) if sys.argv[1] == "broadcast": while True: