mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Improve logging for TeePopen.timeout exceeded
This commit is contained in:
parent
4e0dd08f8c
commit
f092b46025
@ -29,11 +29,13 @@ class TeePopen:
|
||||
self.env = env or os.environ.copy()
|
||||
self._process = None # type: Optional[Popen]
|
||||
self.timeout = timeout
|
||||
self.timeout_exceeded = False
|
||||
|
||||
def _check_timeout(self) -> None:
|
||||
if self.timeout is None:
|
||||
return
|
||||
sleep(self.timeout)
|
||||
self.timeout_exceeded = True
|
||||
while self.process.poll() is None:
|
||||
logging.warning(
|
||||
"Killing process %s, timeout %s exceeded",
|
||||
@ -62,6 +64,16 @@ class TeePopen:
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
self.wait()
|
||||
if self.timeout_exceeded:
|
||||
exceeded_log = (
|
||||
f"Command `{self.command}` has failed, "
|
||||
f"timeout {self.timeout}s is exceeded"
|
||||
)
|
||||
if self.process.stdout is not None:
|
||||
sys.stdout.write(exceeded_log)
|
||||
|
||||
self.log_file.write(exceeded_log)
|
||||
|
||||
self.log_file.close()
|
||||
|
||||
def wait(self) -> int:
|
||||
|
Loading…
Reference in New Issue
Block a user