Notice
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- error
- TensorFlow
- Anaconda
- python
- colaboratory
- keras
- linux
- shakeratos
- face_recognition
- python3
- gpu memory
- 딥러닝
- ppc64le
- download
- dlib
- Windows 10
- ubuntu
- windows
- FIle
- dataset
- raspberry pi
- urllib
- Jupyter notebook
- install
- CUDA
- YouTube 8M
- object detection
- Deep Learning
- colab
- pyTorch
Archives
- Today
- Total
Shakerato
Set timeout for urllib urlretrieve download files 본문
1. Basic code of urlretrieve to download a file
urllib.request.urlretrieve(source_url, destination_path)
2. Advanced code of urlretrive to display the download percentage.
def download_file(source_url, destination_path):
"""Downloads `source_url` onto `destionation_path`."""
def _progress(count, block_size, total_size):
sys.stderr.write('\r>> Downloading %s %.1f%%' % (
source_url, float(count * block_size) / float(total_size) * 100.0))
sys.stderr.flush()
urllib.request.urlretrieve(source_url, destination_path, _progress)
3. Set timeout for urlretrive when download is stopping
(Below code can be placed on the top of the code)
(30 seconds)
import socket
socket.setdefaulttimeout(30)
4.Set retries count
def download_file(source_url, destination_path, retries=3):
def _progress(count, block_size, total_size):
sys.stderr.write('\r>> Downloading %s %.1f%%' % (
source_url, float(count * block_size) / float(total_size) * 100.0))
sys.stderr.flush()
while(retries > 0):
try:
urllib.request.urlretrieve(source_url, destination_path, _progress)
break
except:
print("retry")
retries = retries - 1
continue
'Research' 카테고리의 다른 글
pytorch "RuntimeError: ~ inplace operation" for CUDA (0) | 2019.01.05 |
---|---|
CUDA 9.2가 깔려있어도 CUDA 9.0을 참조해 에러나는경우, ImportError: libcublas.so.9.0 (0) | 2018.09.07 |
'no module named six.moves' in ubuntu (0) | 2018.08.17 |
pycocotools install on Windows 10, jupyter notebook (0) | 2018.08.09 |
dlib(cuda enabled), face_recognition ubuntu 16.04에 설치하기 (0) | 2018.08.08 |
Comments