Skip to content

Commit 508cb59

Browse files
fix: use subprocess instead of os.system in resume.py (#13730)
fix: V-001 security vulnerability Automated security fix generated by Orbis Security AI Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
1 parent 3a82ac0 commit 508cb59

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

utils/aws/resume.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Resume all interrupted trainings in yolov5/ dir including DDP trainings
44
# Usage: $ python utils/aws/resume.py
55

6-
import os
6+
import subprocess
77
import sys
88
from pathlib import Path
99

@@ -34,10 +34,20 @@
3434

3535
if ddp: # multi-GPU
3636
port += 1
37-
cmd = f"python -m torch.distributed.run --nproc_per_node {nd} --master_port {port} train.py --resume {last}"
37+
cmd = [
38+
"python",
39+
"-m",
40+
"torch.distributed.run",
41+
"--nproc_per_node",
42+
str(nd),
43+
"--master_port",
44+
str(port),
45+
"train.py",
46+
"--resume",
47+
str(last),
48+
]
3849
else: # single-GPU
39-
cmd = f"python train.py --resume {last}"
50+
cmd = ["python", "train.py", "--resume", str(last)]
4051

41-
cmd += " > /dev/null 2>&1 &" # redirect output to dev/null and run in daemon thread
42-
print(cmd)
43-
os.system(cmd)
52+
print(" ".join(cmd))
53+
subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # run in daemon thread

0 commit comments

Comments
 (0)