Skip to content
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

sigterm to workers #2129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 20 additions & 3 deletions metaflow/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,16 @@ def _killall(self):
# If we are here, all children have received a signal and are shutting down.
# We want to give them an opportunity to do so and then kill
live_workers = set(self._workers.values())
now = int(time.time())
self._logger(
"Terminating %d active tasks..." % len(live_workers),
"Attempting graceful shutdown of %d active tasks..." % len(live_workers),
system_msg=True,
bad=True,
)

for each_worker in live_workers:
each_worker.shutdown()

now = int(time.time())
while live_workers and int(time.time()) - now < 5:
# While not all workers are dead and we have waited less than 5 seconds
live_workers = [worker for worker in live_workers if not worker.clean()]
Expand Down Expand Up @@ -1523,6 +1527,8 @@ def __init__(self, task, max_logs_size):
}

self._encoding = sys.stdout.encoding or "UTF-8"
self.terminated = False
# Terminated indicates that SIGTERM was sent to the task
self.killed = False # Killed indicates that the task was forcibly killed
# with SIGKILL by the master process.
# A killed task is always considered cleaned
Expand Down Expand Up @@ -1622,11 +1628,22 @@ def clean(self):
return True
if not self.cleaned:
for fileobj, buf in self._logs.values():
msg = b"[KILLED BY ORCHESTRATOR]\n"
if self.terminated:
msg = b"[TERMINATED BY ORCHESTRATOR]\n"
else:
msg = b"[KILLED BY ORCHESTRATOR]\n"
self.emit_log(msg, buf, system_msg=True)
self.cleaned = True
return self._proc.poll() is not None

def shutdown(self):
if not self.terminated:
try:
self._proc.terminate()
except:
pass
self.terminated = True

def kill(self):
if not self.killed:
try:
Expand Down
Loading