diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-09-04 23:17:34 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-09-04 23:17:34 +0200 |
| commit | 4844bbadc7fa9ac0b6640cd1010cce8e603ea4dd (patch) | |
| tree | cb9c23bcb42e820ebe53eb4a3c28beee72ec2723 | |
| parent | 9b16092031b306c7dc49dde70df74461ebea4a23 (diff) | |
| download | allocbench-4844bbadc7fa9ac0b6640cd1010cce8e603ea4dd.tar.gz allocbench-4844bbadc7fa9ac0b6640cd1010cce8e603ea4dd.zip | |
rework Benchmark.terminate_subprocess to use Popen.communicate
code is inspired by the example in the python3 subprocess documentation
| -rw-r--r-- | src/benchmark.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/benchmark.py b/src/benchmark.py index d94cc52..a31552b 100644 --- a/src/benchmark.py +++ b/src/benchmark.py @@ -34,23 +34,25 @@ class Benchmark: "allocators": copy.deepcopy(src.globalvars.allocators)} @staticmethod - def terminate_subprocess(popen, timeout=5): + def terminate_subprocess(proc, timeout=5): """Terminate or kill a Popen object""" # Skip already terminated subprocess - if popen.poll() is not None: + if proc.poll() is not None: return - print_info("Terminating subprocess", popen.args) - popen.terminate() + print_info("Terminating subprocess", proc.args) + proc.terminate() try: - print_info("Subprocess exited with ", popen.wait(timeout=timeout)) + outs, errs = proc.communicate(timeout=timeout) + print_info("Subprocess exited with ", proc.returncode) except subprocess.TimeoutExpired: - print_error("Killing subprocess ", popen.args) - popen.kill() - popen.wait() - print_debug("Server Out:", popen.stdout.read()) - print_debug("Server Err:", popen.stderr.read()) + print_error("Killing subprocess ", proc.args) + proc.kill() + outs, errs = proc.communicate() + + print_debug("Server Out:", outs) + print_debug("Server Err:", errs) @staticmethod def scale_threads_for_cpus(factor, steps=None): |
