From 7412b142f1629de68671310e36428edba232b3bd Mon Sep 17 00:00:00 2001 From: Newnius Date: Sat, 11 Apr 2020 10:51:51 +0800 Subject: [PATCH] launch in background --- agent.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/agent.py b/agent.py index 62919f9..1f26d23 100644 --- a/agent.py +++ b/agent.py @@ -28,6 +28,21 @@ ver = 0 last_version = {} +def launch_task_in_background(container, task_id): + script = " ".join([ + "docker exec", + task_id, + "pkill", + "sleep" + ]) + + while True: + code = container.exec_run('sh -c \'' + script + '\'').exit_code + if code == 0: + break + time.sleep(0.1) + + def launch_tasks(stats): utils = {} for stat in stats: @@ -40,18 +55,9 @@ def launch_tasks(stats): for task_id, task in pending_tasks.items(): if int(utils[task['gpus'][0]]) < 60: entries_to_remove.append(task_id) - script = " ".join([ - "docker exec", - task_id, - "pkill", - "sleep" - ]) - while True: - code = container.exec_run('sh -c \'' + script + '\'').exit_code - if code == 0: - break - time.sleep(0.1) + t = Thread(target=launch_task_in_background, name='launch_task', args=(container, task_id,)) + t.start() for k in entries_to_remove: pending_tasks.pop(k, None)