mirror of
https://github.com/clearml/clearml-agent
synced 2025-03-03 18:52:22 +00:00
Change daemon --stop without any specific flag to terminate the agents by worker id lexicographic order
This commit is contained in:
parent
94997f9c88
commit
17d2bf2a3e
@ -707,9 +707,10 @@ class Worker(ServiceCommandSection):
|
|||||||
kwargs = self._verify_command_states(kwargs)
|
kwargs = self._verify_command_states(kwargs)
|
||||||
docker = docker or kwargs.get('docker')
|
docker = docker or kwargs.get('docker')
|
||||||
|
|
||||||
|
# We are not running a daemon we are killing one.
|
||||||
|
# find the pid send termination signal and leave
|
||||||
if kwargs.get('stop', False):
|
if kwargs.get('stop', False):
|
||||||
self._kill_daemon()
|
return 1 if not self._kill_daemon() else 0
|
||||||
return
|
|
||||||
|
|
||||||
# make sure we only have a single instance,
|
# make sure we only have a single instance,
|
||||||
# also make sure we set worker_id properly and cache folders
|
# also make sure we set worker_id properly and cache folders
|
||||||
@ -2355,7 +2356,7 @@ class Worker(ServiceCommandSection):
|
|||||||
def _kill_daemon(self):
|
def _kill_daemon(self):
|
||||||
worker_id, worker_name = self._generate_worker_id_name()
|
worker_id, worker_name = self._generate_worker_id_name()
|
||||||
# Iterate over all running process
|
# Iterate over all running process
|
||||||
for pid, uid, slot, file in Singleton.get_running_pids():
|
for pid, uid, slot, file in sorted(Singleton.get_running_pids(), key=lambda x: x[1] or ''):
|
||||||
# wither we have a match for the worker_id or we just pick the first one
|
# wither we have a match for the worker_id or we just pick the first one
|
||||||
if pid >= 0 and (
|
if pid >= 0 and (
|
||||||
(worker_id and uid == worker_id) or
|
(worker_id and uid == worker_id) or
|
||||||
|
@ -65,6 +65,7 @@ def terminate_process(pid, timeout=10.):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def kill_all_child_processes(pid=None):
|
def kill_all_child_processes(pid=None):
|
||||||
# get current process if pid not provided
|
# get current process if pid not provided
|
||||||
include_parent = True
|
include_parent = True
|
||||||
|
Loading…
Reference in New Issue
Block a user