Skip to content

Commit 82960dc

Browse files
authored
replace os.wait with time.sleep (#245)
1 parent 1ac3dfa commit 82960dc

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

contextily/tile.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tools for downloading map tiles from coordinates."""
2+
23
from __future__ import absolute_import, division, print_function
34

45
import uuid
@@ -7,7 +8,7 @@
78
import requests
89
import atexit
910
import io
10-
import os
11+
import time
1112
import shutil
1213
import tempfile
1314
import warnings
@@ -140,8 +141,17 @@ def bounds2raster(
140141
w, s = _sm2ll(w, s)
141142
e, n = _sm2ll(e, n)
142143
# Download
143-
Z, ext = bounds2img(w, s, e, n, zoom=zoom, source=source, ll=True, n_connections=n_connections,
144-
use_cache=use_cache)
144+
Z, ext = bounds2img(
145+
w,
146+
s,
147+
e,
148+
n,
149+
zoom=zoom,
150+
source=source,
151+
ll=True,
152+
n_connections=n_connections,
153+
use_cache=use_cache,
154+
)
145155

146156
# Write
147157
# ---
@@ -171,7 +181,18 @@ def bounds2raster(
171181

172182

173183
def bounds2img(
174-
w, s, e, n, zoom="auto", source=None, ll=False, wait=0, max_retries=2, n_connections=1, use_cache=True, zoom_adjust=None
184+
w,
185+
s,
186+
e,
187+
n,
188+
zoom="auto",
189+
source=None,
190+
ll=False,
191+
wait=0,
192+
max_retries=2,
193+
n_connections=1,
194+
use_cache=True,
195+
zoom_adjust=None,
175196
):
176197
"""
177198
Take bounding box and zoom and return an image with all the tiles
@@ -251,16 +272,17 @@ def bounds2img(
251272
tile_urls = [provider.build_url(x=tile.x, y=tile.y, z=tile.z) for tile in tiles]
252273
# download tiles
253274
if n_connections < 1 or not isinstance(n_connections, int):
254-
raise ValueError(
255-
f"n_connections must be a positive integer value."
256-
)
275+
raise ValueError(f"n_connections must be a positive integer value.")
257276
# Use threads for a single connection to avoid the overhead of spawning a process. Use processes for multiple
258277
# connections if caching is enabled, as threads lead to memory issues when used in combination with the joblib
259278
# memory caching (used for the _fetch_tile() function).
260-
preferred_backend = "threads" if (n_connections == 1 or not use_cache) else "processes"
279+
preferred_backend = (
280+
"threads" if (n_connections == 1 or not use_cache) else "processes"
281+
)
261282
fetch_tile_fn = memory.cache(_fetch_tile) if use_cache else _fetch_tile
262283
arrays = Parallel(n_jobs=n_connections, prefer=preferred_backend)(
263-
delayed(fetch_tile_fn)(tile_url, wait, max_retries) for tile_url in tile_urls)
284+
delayed(fetch_tile_fn)(tile_url, wait, max_retries) for tile_url in tile_urls
285+
)
264286
# merge downloaded tiles
265287
merged, extent = _merge_tiles(tiles, arrays)
266288
# lon/lat extent --> Spheric Mercator
@@ -444,14 +466,13 @@ def _retryer(tile_url, wait, max_retries):
444466
)
445467
elif request.status_code == 104 or request.status_code == 200:
446468
if max_retries > 0:
447-
os.wait(wait)
469+
time.sleep(wait)
448470
max_retries -= 1
449471
request = _retryer(tile_url, wait, max_retries)
450472
else:
451473
raise requests.HTTPError("Connection reset by peer too many times.")
452474

453475

454-
455476
def howmany(w, s, e, n, zoom, verbose=True, ll=False):
456477
"""
457478
Number of tiles required for a given bounding box and a zoom level

0 commit comments

Comments
 (0)