TLDR: stuck with this https://code.google.com/archive/p/byte-unixbench/issues/1
Trying to run UnixBench using subprocess.popen()
while capturing output and printing it out in realtime.
This is the subroutine I've come up with:
def run_and_print(command, cwd=None, catch_stderr = False):
if catch_stderr:
err_pipe = subprocess.PIPE
else:
err_pipe = subprocess.STDOUT
p = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=1, cwd=cwd, stderr=err_pipe)
r = ''
while True:
if catch_stderr:
out = p.stderr.read(1)
else:
out = p.stdout.read(1)
if out == "" and p.poll() != None:
break
sys.stdout.write(out)
sys.stdout.flush()
r += out
return r
It works just fine for all the purposes except for UnixBench. Unixbench just dies after a while:
unixbench = run_and_print(['./Run'])
...
1 x Pipe Throughput 1 2 3 4 5 6 7 8 9 10
1 x Pipe-based Context Switching 1 2 3 4
Run: "Pipe-based Context Switching": slave write failed: Broken pipe; aborting
Google didn't help much. The only meaningful result I've got is https://code.google.com/archive/p/byte-unixbench/issues/1 and suggest solution to create a java app won't work for me as I need to run the script with as few dependencies as possible.
I'll be thankful for any solution or a workaround. The system I'm testing this on is Ubuntu 14.04.4 x64