Skip to content

Commit 2586930

Browse files
author
Jacob Pennington
committed
Fixed urllib typo in kilosort.utils, reduced download retries
1 parent a6466c2 commit 2586930

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

kilosort/utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import numpy as np
1010
from tqdm import tqdm
11-
from urllib.request import urlopen
12-
from urllib.error import HTTPError
1311

1412
import torch
1513

@@ -58,23 +56,24 @@ def download_probes(probe_dir=None):
5856
logger.info('Downloading: "{}" to {}\n'.format(url, cached_file))
5957
try:
6058
download_url_to_file(url, cached_file, progress=True)
61-
except HTTPError as e:
59+
except urllib.error.HTTPError as e:
6260
logger.info(f'Unable to download probe {probe_name}, error:')
6361
logger.info(e)
6462

6563

66-
def retry_download(func, n_tries=10):
64+
def retry_download(func, n_tries=5):
6765
def retry(*args, **kwargs):
6866
i = 0
6967
while True:
7068
try:
7169
func(*args, **kwargs)
7270
break
73-
except urllib.error.HTTPerror as e:
71+
except urllib.error.HTTPError as e:
7472
# Try it several times, wait a couple seconds between attempts.
7573
if i < n_tries:
74+
print(f'Download failed, retrying... {i}/{n_tries-1}')
7675
i += 1
77-
time.sleep(2)
76+
time.sleep(1)
7877
else:
7978
raise e
8079

@@ -94,7 +93,7 @@ def download_url_to_file(url, dst, progress=True):
9493
file_size = None
9594
import ssl
9695
ssl._create_default_https_context = ssl._create_unverified_context
97-
u = urlopen(url)
96+
u = urllib.request.urlopen(url)
9897
meta = u.info()
9998
if hasattr(meta, 'getheaders'):
10099
content_length = meta.getheaders("Content-Length")

0 commit comments

Comments
 (0)