diff --git a/sky/backends/backend_utils.py b/sky/backends/backend_utils.py index 541d3bf96ef..1dc132ce221 100644 --- a/sky/backends/backend_utils.py +++ b/sky/backends/backend_utils.py @@ -1996,9 +1996,11 @@ def kill_children_processes(): # Handle ctrl-c def interrupt_handler(signum, frame): del signum, frame - logger.warning(f'{colorama.Style.DIM}The job will keep ' - f'running after Ctrl-C.{colorama.Style.RESET_ALL}') kill_children_processes() + # Avoid using logger here, as it will print the stack trace for broken + # pipe, when the output is piped to another program. + print(f'{colorama.Style.DIM}Tip: The job will keep ' + f'running after Ctrl-C.{colorama.Style.RESET_ALL}') with ux_utils.print_exception_no_traceback(): raise KeyboardInterrupt(exceptions.KEYBOARD_INTERRUPT_CODE) @@ -2006,9 +2008,11 @@ def interrupt_handler(signum, frame): # Handle ctrl-z def stop_handler(signum, frame): del signum, frame - logger.warning(f'{colorama.Style.DIM}The job will keep ' - f'running after Ctrl-Z.{colorama.Style.RESET_ALL}') kill_children_processes() + # Avoid using logger here, as it will print the stack trace for broken + # pipe, when the output is piped to another program. + print(f'{colorama.Style.DIM}Tip: The job will keep ' + f'running after Ctrl-Z.{colorama.Style.RESET_ALL}') with ux_utils.print_exception_no_traceback(): raise KeyboardInterrupt(exceptions.SIGTSTP_CODE) diff --git a/sky/skylet/log_lib.py b/sky/skylet/log_lib.py index dca32ec3c98..a8ede3f570c 100644 --- a/sky/skylet/log_lib.py +++ b/sky/skylet/log_lib.py @@ -417,6 +417,7 @@ def tail_logs(job_owner: str, time.sleep(_SKY_LOG_WAITING_GAP_SECONDS) status = job_lib.update_job_status(job_owner, [job_id], silent=True)[0] + start_stream_at = 'INFO: Tip: use Ctrl-C to exit log' if follow and status in [ job_lib.JobStatus.RUNNING, job_lib.JobStatus.PENDING ]: @@ -425,15 +426,19 @@ def tail_logs(job_owner: str, with open(log_path, 'r', newline='') as log_file: # Using `_follow` instead of `tail -f` to streaming the whole # log and creating a new process for tail. - for line in _follow_job_logs( - log_file, - job_id=job_id, - start_streaming_at='INFO: Tip: use Ctrl-C to exit log'): + for line in _follow_job_logs(log_file, + job_id=job_id, + start_streaming_at=start_stream_at): print(line, end='', flush=True) else: try: + start_stream = False with open(log_path, 'r') as f: - print(f.read()) + for line in f.readlines(): + if start_stream_at in line: + start_stream = True + if start_stream: + print(line, end='', flush=True) except FileNotFoundError: print(f'{colorama.Fore.RED}ERROR: Logs for job {job_id} (status:' f' {status.value}) does not exist.{colorama.Style.RESET_ALL}')