From 32a5e363f7bb72be6e0c4920b2672c147fee8024 Mon Sep 17 00:00:00 2001 From: Christopher Cooper Date: Tue, 10 Dec 2024 17:46:12 -0800 Subject: [PATCH] fix lint --- sky/jobs/utils.py | 8 ++++---- sky/skylet/log_lib.py | 16 ++++++++-------- sky/skylet/log_lib.pyi | 3 +++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/sky/jobs/utils.py b/sky/jobs/utils.py index 13d07fc2cbb..96a2fbff93d 100644 --- a/sky/jobs/utils.py +++ b/sky/jobs/utils.py @@ -9,7 +9,6 @@ import inspect import os import pathlib -import psutil import shlex import shutil import textwrap @@ -19,6 +18,7 @@ import colorama import filelock +import psutil from typing_extensions import Literal from sky import backends @@ -591,7 +591,7 @@ def stream_logs(job_id: Optional[int], # is not considered an exceptional case. return '' - time.sleep(log_lib._SKY_LOG_WAITING_GAP_SECONDS) + time.sleep(log_lib.SKY_LOG_WAITING_GAP_SECONDS) # See also log_lib.tail_logs. with open(controller_log_path, 'r', newline='', encoding='utf-8') as f: @@ -613,10 +613,10 @@ def stream_logs(job_id: Optional[int], if job_status.is_terminal(): break - time.sleep(log_lib._SKY_LOG_TAILING_GAP_SECONDS) + time.sleep(log_lib.SKY_LOG_TAILING_GAP_SECONDS) # Wait for final logs to be written. - time.sleep(1 + log_lib._SKY_LOG_TAILING_GAP_SECONDS) + time.sleep(1 + log_lib.SKY_LOG_TAILING_GAP_SECONDS) # Print any remaining logs including incomplete line. print(f.read(), end='', flush=True) diff --git a/sky/skylet/log_lib.py b/sky/skylet/log_lib.py index 8a40982972a..ac2b488baf0 100644 --- a/sky/skylet/log_lib.py +++ b/sky/skylet/log_lib.py @@ -25,9 +25,9 @@ from sky.utils import subprocess_utils from sky.utils import ux_utils -_SKY_LOG_WAITING_GAP_SECONDS = 1 -_SKY_LOG_WAITING_MAX_RETRY = 5 -_SKY_LOG_TAILING_GAP_SECONDS = 0.2 +SKY_LOG_WAITING_GAP_SECONDS = 1 +SKY_LOG_WAITING_MAX_RETRY = 5 +SKY_LOG_TAILING_GAP_SECONDS = 0.2 # Peek the head of the lines to check if we need to start # streaming when tail > 0. PEEK_HEAD_LINES_FOR_START_STREAM = 20 @@ -336,7 +336,7 @@ def _follow_job_logs(file, ]: if wait_last_logs: # Wait all the logs are printed before exit. - time.sleep(1 + _SKY_LOG_TAILING_GAP_SECONDS) + time.sleep(1 + SKY_LOG_TAILING_GAP_SECONDS) wait_last_logs = False continue status_str = status.value if status is not None else 'None' @@ -345,7 +345,7 @@ def _follow_job_logs(file, f'Job finished (status: {status_str}).')) return - time.sleep(_SKY_LOG_TAILING_GAP_SECONDS) + time.sleep(SKY_LOG_TAILING_GAP_SECONDS) status = job_lib.get_status_no_lock(job_id) @@ -426,15 +426,15 @@ def tail_logs(job_id: Optional[int], retry_cnt += 1 if os.path.exists(log_path) and status != job_lib.JobStatus.INIT: break - if retry_cnt >= _SKY_LOG_WAITING_MAX_RETRY: + if retry_cnt >= SKY_LOG_WAITING_MAX_RETRY: print( f'{colorama.Fore.RED}ERROR: Logs for ' f'{job_str} (status: {status.value}) does not exist ' f'after retrying {retry_cnt} times.{colorama.Style.RESET_ALL}') return - print(f'INFO: Waiting {_SKY_LOG_WAITING_GAP_SECONDS}s for the logs ' + print(f'INFO: Waiting {SKY_LOG_WAITING_GAP_SECONDS}s for the logs ' 'to be written...') - time.sleep(_SKY_LOG_WAITING_GAP_SECONDS) + time.sleep(SKY_LOG_WAITING_GAP_SECONDS) status = job_lib.update_job_status([job_id], silent=True)[0] start_stream_at = LOG_FILE_START_STREAMING_AT diff --git a/sky/skylet/log_lib.pyi b/sky/skylet/log_lib.pyi index 89d1628ec11..c7028e121aa 100644 --- a/sky/skylet/log_lib.pyi +++ b/sky/skylet/log_lib.pyi @@ -13,6 +13,9 @@ from sky.skylet import constants as constants from sky.skylet import job_lib as job_lib from sky.utils import log_utils as log_utils +SKY_LOG_WAITING_GAP_SECONDS: int = ... +SKY_LOG_WAITING_MAX_RETRY: int = ... +SKY_LOG_TAILING_GAP_SECONDS: float = ... LOG_FILE_START_STREAMING_AT: str = ...