Skip to content

Commit

Permalink
[UX] remove stacktrace for pipe and ssh info (skypilot-org#1324)
Browse files Browse the repository at this point in the history
* UX: remove stacktrace for pipe and ssh info

* Add comment

* Avoid ray output in the logs

* format

* revert ssh quiet option
  • Loading branch information
Michaelvll authored and Sumanth committed Jan 15, 2023
1 parent fd3086f commit ee44166
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
12 changes: 8 additions & 4 deletions sky/backends/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1997,19 +1997,23 @@ 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)


# 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)

Expand Down
15 changes: 10 additions & 5 deletions sky/skylet/log_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]:
Expand All @@ -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}')

0 comments on commit ee44166

Please sign in to comment.