Add threaded stdout to fix accumulating data on server
This commit is contained in:
parent
610a3429dd
commit
ccac19df6c
@ -20,11 +20,24 @@ sp = pUp(s)
|
|||||||
# script start
|
# script start
|
||||||
import subprocess
|
import subprocess
|
||||||
import socket
|
import socket
|
||||||
|
import threading
|
||||||
|
import queue
|
||||||
|
|
||||||
bufferSize = 1000 # buffer size in bytes
|
bufferSize = 1000 # buffer size in bytes
|
||||||
serverAddr = ("127.0.0.1",12000)
|
serverAddr = ("127.0.0.1",12000)
|
||||||
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
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):
|
def listToCommand(lst):
|
||||||
cmd = ""
|
cmd = ""
|
||||||
for arg in lst:
|
for arg in lst:
|
||||||
@ -49,10 +62,12 @@ def main():
|
|||||||
connection.sendall(makePayload(sys.argv[1:]))
|
connection.sendall(makePayload(sys.argv[1:]))
|
||||||
|
|
||||||
if sys.argv[1] == "watch":
|
if sys.argv[1] == "watch":
|
||||||
|
stdoutThr = stdoutThread()
|
||||||
|
stdoutThr.start()
|
||||||
while True:
|
while True:
|
||||||
data = connection.recv(bufferSize)
|
data = connection.recv(bufferSize)
|
||||||
if data == b"": return
|
if data == b"": return
|
||||||
sys.stdout.buffer.write(data)
|
stdoutThr.queue.put(data)
|
||||||
|
|
||||||
if sys.argv[1] == "broadcast":
|
if sys.argv[1] == "broadcast":
|
||||||
while True:
|
while True:
|
||||||
|
Loading…
Reference in New Issue
Block a user