Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wget download #59957

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions python/paddle/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import tarfile
import time
import zipfile
from urllib.parse import urlparse

import httpx

Expand Down Expand Up @@ -196,22 +197,31 @@ def _get_download(url, fullname):
return False


def _wget_download(url, fullname):
# using wget to download url
tmp_fullname = fullname + "_tmp"
# –user-agent
command = f'wget -O {tmp_fullname} -t {DOWNLOAD_RETRY_LIMIT} {url}'
subprc = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
_ = subprc.communicate()

if subprc.returncode != 0:
raise RuntimeError(
f'{command} failed. Please make sure `wget` is installed or {url} exists'
def _wget_download(url: str, fullname: str):
try:
assert urlparse(url).scheme in (
'http',
'https',
), 'Only support https and http url'
# using wget to download url
tmp_fullname = fullname + "_tmp"
# –user-agent
command = f'wget -O {tmp_fullname} -t {DOWNLOAD_RETRY_LIMIT} {url}'
subprc = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
_ = subprc.communicate()

if subprc.returncode != 0:
raise RuntimeError(
f'{command} failed. Please make sure `wget` is installed or {url} exists'
)

shutil.move(tmp_fullname, fullname)

shutil.move(tmp_fullname, fullname)
except Exception as e: # requests.exceptions.ConnectionError
logger.info(f"Downloading {url} failed with exception {str(e)}")
return False

return fullname

Expand Down