Attempt at process pipe full close

This commit is contained in:
Carlos Sanchez 2024-02-01 22:21:04 -05:00 committed by Fierelier
parent f291f341fa
commit df7fcd2967
4 changed files with 54 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/users/
/client/config/
*.swp

View File

@ -14,6 +14,8 @@ sp = pUp(s)
import toml
import subprocess
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
def addressStr(addr):
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[-1],stdin=procs[-1].stdout))
for proc in reversed(procs):
proc.wait()
# Pwetty pwease add thew funcshun owo uwu xoxoxox
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()

View File

@ -44,10 +44,10 @@ def listToCommand(lst):
def recv(conn,l):
start = time.process_time()
timeo = conn.gettimeout()
bytes = b""
bytes = bytearray()
while l > 0:
b = conn.recv(l)
if b == b"": raise ConnectionResetError
if not b: raise ConnectionResetError
if time.process_time() - start > timeo: raise TimeoutError
bytes += b
l -= len(b)
@ -114,11 +114,11 @@ def main():
eprint("Receiving token...")
while True:
data = connection.recv(bufferSize)
if data != b"":
if data:
token += data
continue
if token == b"":
if not token:
eprint("Connection closed: failure")
os.exit(1)
else:
@ -134,7 +134,7 @@ def main():
eprint("Receiving data...")
while True:
data = connection.recv(bufferSize)
if data == b"":
if not data:
eprint("Connection closed.")
return
unbufferedStdout.write(data)
@ -147,7 +147,7 @@ def main():
eprint("Sending data...")
while True:
data = sys.stdin.buffer.read(bufferSizeStdin)
if data == b"":
if not data:
return
connection.sendall(data)
except:

View File

@ -14,6 +14,8 @@ sp = pUp(s)
import toml
import subprocess
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
def addressStr(addr):
return addr[0] + ":" + str(addr[1])
@ -81,8 +83,26 @@ def main():
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[-1],stdin=procs[-1].stdout))
for proc in reversed(procs):
proc.wait()
# Pwetty pwease add thew funcshun owo uwu xoxoxox (<S-F10>)
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()