Skip to content

Commit

Permalink
improved start
Browse files Browse the repository at this point in the history
  • Loading branch information
shadeofblue committed Oct 11, 2023
1 parent 2791c62 commit 5ce4724
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions subprocess_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,22 @@

print(f"Launching: {cmd}, new_session={bool(args.new_session)}")

with open(OUTFILE, "w") as outfile, open(ERRFILE, "w") as errfile:
proc = subprocess.Popen(
cmd,
stdout=outfile,
stderr=errfile,
start_new_session=bool(args.new_session),
)
proc = subprocess.Popen(
cmd,
stdout=open(OUTFILE, "w") ,
stderr=open(ERRFILE, "w"),
start_new_session=bool(args.new_session),
)

launch_count = args.launch_count

while launch_count > 0:
try:
out, err = proc.communicate(timeout=1)
with open(OUTFILE, "r") as outfile, open(ERRFILE, "r") as errfile:
print(
f"exited {launch_count}\n"
f"-- out --\n{outfile.read()}\n-- err --\n{errfile.read()}"
f"-- out --\n{str(out)}\n-- err --\n{str(err)}"
)
proc.communicate(timeout=1)
print(
f"exited {launch_count}\n"
f"-- out --\n{open(OUTFILE, 'r').read()}\n-- err --\n{open(ERRFILE, 'r').read()}"
)
break
except subprocess.TimeoutExpired:
pass
Expand Down

0 comments on commit 5ce4724

Please sign in to comment.