Add threaded stdout to fix accumulating data on server

This commit is contained in:
Fierelier 2021-04-14 17:06:44 +02:00
parent 610a3429dd
commit ccac19df6c

View File

@ -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: