From 6df0f81ca037e139b8c37f2d1c46745ca6305f31 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Wed, 11 Nov 2020 16:32:47 +0200 Subject: [PATCH] Fix uid is None causes ValueError in str.startswith(). Fix str.split (should be on the filename itself, not the path). --- trains_agent/commands/worker.py | 2 +- trains_agent/helper/singleton.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/trains_agent/commands/worker.py b/trains_agent/commands/worker.py index 4dcfaed..07317ef 100644 --- a/trains_agent/commands/worker.py +++ b/trains_agent/commands/worker.py @@ -2520,7 +2520,7 @@ class Worker(ServiceCommandSection): # Iterate over all running process 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 - if pid >= 0 and ( + if pid >= 0 and uid is not None and ( (worker_id and uid == worker_id) or (not worker_id and uid.startswith('{}:'.format(worker_name)))): # this is us kill it diff --git a/trains_agent/helper/singleton.py b/trains_agent/helper/singleton.py index e51f2ac..53d6543 100644 --- a/trains_agent/helper/singleton.py +++ b/trains_agent/helper/singleton.py @@ -4,6 +4,8 @@ from time import sleep from glob import glob from tempfile import gettempdir, NamedTemporaryFile +from typing import List, Tuple, Optional + from trains_agent.definitions import ENV_DOCKER_HOST_MOUNT from trains_agent.helper.base import warning @@ -84,11 +86,12 @@ class Singleton(object): @classmethod def get_running_pids(cls): + # type: () -> List[Tuple[int, Optional[str], Optional[int], str]] temp_folder = cls._get_temp_folder() files = glob(os.path.join(temp_folder, cls.prefix + cls.sep + '*' + cls.ext)) pids = [] for file in files: - parts = file.split(cls.sep) + parts = os.path.basename(file).split(cls.sep) # noinspection PyBroadException try: pid = int(parts[1])