mirror of
https://github.com/newnius/YAO-agent.git
synced 2025-06-07 05:41:56 +00:00
launch in background
This commit is contained in:
parent
bcfeb73ad2
commit
7412b142f1
28
agent.py
28
agent.py
@ -28,6 +28,21 @@ ver = 0
|
|||||||
last_version = {}
|
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):
|
def launch_tasks(stats):
|
||||||
utils = {}
|
utils = {}
|
||||||
for stat in stats:
|
for stat in stats:
|
||||||
@ -40,18 +55,9 @@ def launch_tasks(stats):
|
|||||||
for task_id, task in pending_tasks.items():
|
for task_id, task in pending_tasks.items():
|
||||||
if int(utils[task['gpus'][0]]) < 60:
|
if int(utils[task['gpus'][0]]) < 60:
|
||||||
entries_to_remove.append(task_id)
|
entries_to_remove.append(task_id)
|
||||||
script = " ".join([
|
|
||||||
"docker exec",
|
|
||||||
task_id,
|
|
||||||
"pkill",
|
|
||||||
"sleep"
|
|
||||||
])
|
|
||||||
|
|
||||||
while True:
|
t = Thread(target=launch_task_in_background, name='launch_task', args=(container, task_id,))
|
||||||
code = container.exec_run('sh -c \'' + script + '\'').exit_code
|
t.start()
|
||||||
if code == 0:
|
|
||||||
break
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
for k in entries_to_remove:
|
for k in entries_to_remove:
|
||||||
pending_tasks.pop(k, None)
|
pending_tasks.pop(k, None)
|
||||||
|
Loading…
Reference in New Issue
Block a user