Subprocess improvements (#10973)

* Use list-form arguments for subprocess.run calls where possible

Augments #10944

* Deduplicate curl code

* Avoid eval() to parse integer

---------

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Aarni KoskelaandGlenn Jocher authored and GitHub committed 2023-02-13 18:00:31 +04:00
1 parent 1a2eb532ce
commit a2de5c5bf6
8 files changed
+68 -24

No files matched your search

+2 -4
View File
@@ -38,7 +38,7 @@ import torchvision
import yaml
from utils import TryExcept, emojis
from utils.downloads import gsutil_getsize
from utils.downloads import gsutil_getsize, curl_download
from utils.metrics import box_iou, fitness
FILE = Path(__file__).resolve()
@@ -630,9 +630,7 @@ def download(url, dir='.', unzip=True, delete=True, curl=False, threads=1, retry
LOGGER.info(f'Downloading {url} to {f}...')
for i in range(retry + 1):
if curl:
s = 'sS' if threads > 1 else '' # silent
proc = subprocess.run(f'curl -# -{s}L "{url}" -o "{f}" --retry 9 -C -'.split())
success = proc.returncode == 0
success = curl_download(url, f, silent=(threads > 1))
else:
torch.hub.download_url_to_file(url, f, progress=threads == 1) # torch download
success = f.is_file()