From 8869ec630682a6404797f9e63413ccc3962f8825 Mon Sep 17 00:00:00 2001 From: Domenic Barbuzzi Date: Wed, 29 May 2024 17:51:27 +0000 Subject: [PATCH] Capture output directly --- .../benchmarks/run_benchmark_serving.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/neuralmagic/benchmarks/run_benchmark_serving.py b/neuralmagic/benchmarks/run_benchmark_serving.py index 826949491a06a..368bc08d74919 100644 --- a/neuralmagic/benchmarks/run_benchmark_serving.py +++ b/neuralmagic/benchmarks/run_benchmark_serving.py @@ -6,7 +6,6 @@ import sys import time from pathlib import Path -from tempfile import TemporaryFile from typing import Dict, List, NamedTuple, Optional import requests @@ -30,28 +29,23 @@ def __init__(self, args: Dict, max_ready_wait: int = 600): self.cmd.extend([f"--{k}", str(v)]) self.max_ready_wait = max_ready_wait self.proc = None - self.output_file = TemporaryFile() def __enter__(self): log_banner(self.logger, "server startup command", shlex.join(self.cmd)) self.proc = subprocess.Popen(self.cmd, stderr=subprocess.STDOUT, - stdout=self.output_file.fileno()) + stdout=subprocess.PIPE) self._wait_for_server_ready() def __exit__(self, exc_type, exc_value, exc_traceback): if self.proc and self.proc.poll() is None: self.logger.info("killing server") self.proc.kill() - - if exc_type is None: - return # only log if an exception occurred - - self.output_file.seek(0) - self.output = self.output_file.read() - self.output_file.close() - - log_banner(self.logger, "server output", self.output) + log_banner( + self.logger, "context exit args", f"exc_type={exc_type}\n" + f"exc_value={exc_value}\n" + f"exc_traceback={exc_traceback}") + log_banner(self.logger, "server output", self.proc.stdout) def _wait_for_server_ready(self): self.logger.info("waiting for server to become ready")