Skip to content

fix: spot interruption detection #2391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions metaflow/plugins/aws/batch/batch_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ def task_pre_step(
self._save_logs_sidecar.start()

# Start spot termination monitor sidecar.
# TODO: A nicer way to pass the main process id to a Sidecar, in order to allow sidecars to send signals back to the main process.
os.environ["MF_MAIN_PID"] = str(os.getpid())
current._update_env(
{"spot_termination_notice": "/tmp/spot_termination_notice"}
)
Expand Down
2 changes: 2 additions & 0 deletions metaflow/plugins/kubernetes/kubernetes_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ def task_pre_step(
self._save_logs_sidecar.start()

# Start spot termination monitor sidecar.
# TODO: A nicer way to pass the main process id to a Sidecar, in order to allow sidecars to send signals back to the main process.
os.environ["MF_MAIN_PID"] = str(os.getpid())
current._update_env(
{"spot_termination_notice": "/tmp/spot_termination_notice"}
)
Expand Down
5 changes: 4 additions & 1 deletion metaflow/plugins/kubernetes/spot_monitor_sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def __init__(self):
self._token = None
self._token_expiry = 0

# Due to nesting, os.getppid is not reliable for fetching the main task pid
self.main_pid = int(os.getenv("MF_MAIN_PID", os.getppid()))

if self._is_aws_spot_instance():
self._process = Process(target=self._monitor_loop)
self._process.start()
Expand Down Expand Up @@ -71,7 +74,7 @@ def _monitor_loop(self):
if response.status_code == 200:
termination_time = response.text
self._emit_termination_metadata(termination_time)
os.kill(os.getppid(), signal.SIGTERM)
os.kill(self.main_pid, signal.SIGUSR1)
break
except (requests.exceptions.RequestException, requests.exceptions.Timeout):
pass
Expand Down
Loading