Attempt at process pipe full close
This commit is contained in:
parent
f291f341fa
commit
df7fcd2967
|
@ -1,2 +1,3 @@
|
||||||
/users/
|
/users/
|
||||||
/client/config/
|
/client/config/
|
||||||
|
*.swp
|
|
@ -14,6 +14,8 @@ sp = pUp(s)
|
||||||
import toml
|
import toml
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
def addressStr(addr):
|
def addressStr(addr):
|
||||||
return addr[0] + ":" + str(addr[1])
|
return addr[0] + ":" + str(addr[1])
|
||||||
|
|
||||||
|
@ -100,7 +102,25 @@ def main():
|
||||||
procs.append(subprocess.Popen(cmds[i],stdin=procs[i - 1].stdout,stdout=subprocess.PIPE))
|
procs.append(subprocess.Popen(cmds[i],stdin=procs[i - 1].stdout,stdout=subprocess.PIPE))
|
||||||
procs.append(subprocess.Popen(cmds[-1],stdin=procs[-1].stdout))
|
procs.append(subprocess.Popen(cmds[-1],stdin=procs[-1].stdout))
|
||||||
|
|
||||||
for proc in reversed(procs):
|
# Pwetty pwease add thew funcshun owo uwu xoxoxox
|
||||||
proc.wait()
|
import time
|
||||||
|
running = True
|
||||||
|
while running:
|
||||||
|
for proc in procs:
|
||||||
|
if proc.poll() is not None:
|
||||||
|
eprint("Process died: " + str(proc.args))
|
||||||
|
running = False
|
||||||
|
break
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
eprint("Terminating process chain (" + str(len(procs)) + ")...")
|
||||||
|
|
||||||
|
for proc in procs:
|
||||||
|
eprint("Closing: " + str(proc.args))
|
||||||
|
try:
|
||||||
|
proc.terminate()
|
||||||
|
proc.wait()
|
||||||
|
except Exception as ex:
|
||||||
|
eprint("Error waiting for process!!! " + str(ex))
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -44,10 +44,10 @@ def listToCommand(lst):
|
||||||
def recv(conn,l):
|
def recv(conn,l):
|
||||||
start = time.process_time()
|
start = time.process_time()
|
||||||
timeo = conn.gettimeout()
|
timeo = conn.gettimeout()
|
||||||
bytes = b""
|
bytes = bytearray()
|
||||||
while l > 0:
|
while l > 0:
|
||||||
b = conn.recv(l)
|
b = conn.recv(l)
|
||||||
if b == b"": raise ConnectionResetError
|
if not b: raise ConnectionResetError
|
||||||
if time.process_time() - start > timeo: raise TimeoutError
|
if time.process_time() - start > timeo: raise TimeoutError
|
||||||
bytes += b
|
bytes += b
|
||||||
l -= len(b)
|
l -= len(b)
|
||||||
|
@ -114,11 +114,11 @@ def main():
|
||||||
eprint("Receiving token...")
|
eprint("Receiving token...")
|
||||||
while True:
|
while True:
|
||||||
data = connection.recv(bufferSize)
|
data = connection.recv(bufferSize)
|
||||||
if data != b"":
|
if data:
|
||||||
token += data
|
token += data
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if token == b"":
|
if not token:
|
||||||
eprint("Connection closed: failure")
|
eprint("Connection closed: failure")
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
else:
|
else:
|
||||||
|
@ -134,7 +134,7 @@ def main():
|
||||||
eprint("Receiving data...")
|
eprint("Receiving data...")
|
||||||
while True:
|
while True:
|
||||||
data = connection.recv(bufferSize)
|
data = connection.recv(bufferSize)
|
||||||
if data == b"":
|
if not data:
|
||||||
eprint("Connection closed.")
|
eprint("Connection closed.")
|
||||||
return
|
return
|
||||||
unbufferedStdout.write(data)
|
unbufferedStdout.write(data)
|
||||||
|
@ -147,7 +147,7 @@ def main():
|
||||||
eprint("Sending data...")
|
eprint("Sending data...")
|
||||||
while True:
|
while True:
|
||||||
data = sys.stdin.buffer.read(bufferSizeStdin)
|
data = sys.stdin.buffer.read(bufferSizeStdin)
|
||||||
if data == b"":
|
if not data:
|
||||||
return
|
return
|
||||||
connection.sendall(data)
|
connection.sendall(data)
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -14,6 +14,8 @@ sp = pUp(s)
|
||||||
import toml
|
import toml
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
def addressStr(addr):
|
def addressStr(addr):
|
||||||
return addr[0] + ":" + str(addr[1])
|
return addr[0] + ":" + str(addr[1])
|
||||||
|
|
||||||
|
@ -81,8 +83,26 @@ def main():
|
||||||
for i in range(1,len(cmds) - 1):
|
for i in range(1,len(cmds) - 1):
|
||||||
procs.append(subprocess.Popen(cmds[i],stdin=procs[i - 1].stdout,stdout=subprocess.PIPE))
|
procs.append(subprocess.Popen(cmds[i],stdin=procs[i - 1].stdout,stdout=subprocess.PIPE))
|
||||||
procs.append(subprocess.Popen(cmds[-1],stdin=procs[-1].stdout))
|
procs.append(subprocess.Popen(cmds[-1],stdin=procs[-1].stdout))
|
||||||
|
|
||||||
for proc in reversed(procs):
|
# Pwetty pwease add thew funcshun owo uwu xoxoxox (<S-F10>)
|
||||||
proc.wait()
|
import time
|
||||||
|
running = True
|
||||||
|
while running:
|
||||||
|
for proc in procs:
|
||||||
|
if proc.poll() is not None:
|
||||||
|
eprint("Process died: " + str(proc.args))
|
||||||
|
running = False
|
||||||
|
break
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
eprint("Terminating process chain (" + str(len(procs)) + ")...")
|
||||||
|
|
||||||
|
for proc in procs:
|
||||||
|
eprint("Closing: " + str(proc.args))
|
||||||
|
try:
|
||||||
|
proc.terminate()
|
||||||
|
proc.wait()
|
||||||
|
except Exception as ex:
|
||||||
|
eprint("Error waiting for process!!! " + str(ex))
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue