Skip to content

Commit

Permalink
[Core] Avoid signal when sky.launch is not executed in the main thread (
Browse files Browse the repository at this point in the history
#2252)

* avoid signal when not used in main thread

* avoid signal handling for spot tail logs

* import order
  • Loading branch information
Michaelvll authored Jul 17, 2023
1 parent 3a8ae21 commit 677b2e8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions sky/backends/cloud_vm_ray_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import sys
import tempfile
import textwrap
import threading
import time
import typing
from typing import Dict, Iterable, List, Optional, Tuple, Union, Set
Expand Down Expand Up @@ -3262,8 +3263,9 @@ def tail_logs(self,

# With the stdin=subprocess.DEVNULL, the ctrl-c will not directly
# kill the process, so we need to handle it manually here.
signal.signal(signal.SIGINT, backend_utils.interrupt_handler)
signal.signal(signal.SIGTSTP, backend_utils.stop_handler)
if threading.current_thread() is threading.main_thread():
signal.signal(signal.SIGINT, backend_utils.interrupt_handler)
signal.signal(signal.SIGTSTP, backend_utils.stop_handler)
try:
returncode = self.run_on_head(
handle,
Expand Down Expand Up @@ -3296,8 +3298,9 @@ def tail_spot_logs(self,

# With the stdin=subprocess.DEVNULL, the ctrl-c will not directly
# kill the process, so we need to handle it manually here.
signal.signal(signal.SIGINT, backend_utils.interrupt_handler)
signal.signal(signal.SIGTSTP, backend_utils.stop_handler)
if threading.current_thread() is threading.main_thread():
signal.signal(signal.SIGINT, backend_utils.interrupt_handler)
signal.signal(signal.SIGTSTP, backend_utils.stop_handler)

# Refer to the notes in tail_logs.
self.run_on_head(
Expand Down

0 comments on commit 677b2e8

Please sign in to comment.