From ccac19df6ca894f792cf9ce5051e01a89930cad3 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Wed, 14 Apr 2021 17:06:44 +0200 Subject: [PATCH] Add threaded stdout to fix accumulating data on server --- fstream-client.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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: