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

Add timeout parameter to add_basemap #216

Open
anitagraser opened this issue May 9, 2023 · 1 comment
Open

Add timeout parameter to add_basemap #216

anitagraser opened this issue May 9, 2023 · 1 comment

Comments

@anitagraser
Copy link

I recently discovered that in some setups (for me specifically: WSL in my company VPN), add_basemap gets stuck forever. It seems to fail to load the tiles and there is no way to specify a timeout.

This is my current workaround but it would be much more convenient to just be able to specify timeout=5 in add_basemap:

import signal

class TimeoutError(Exception):
    pass

def timeout_handler(signum, frame):
    raise TimeoutError("Timed out")

ax = gdf().to_crs(3857).plot()

# Set a timer for 5 seconds
try:  # SIGALRM is only available on UNIX
    signal.signal(signal.SIGALRM, timeout_handler)
    signal.alarm(5)
except AttributeError:
    pass 

try:  # add_basemap gets stuck on WSL when in VPN, therefore
    cx.add_basemap(ax)
except TimeoutError:
    print("Timed out while running add_basemap")

ax.figure.savefig('plot.png')
@martinfleis
Copy link
Member

Hi, yes, it would make sense to expose a timeout keyword anywhere where we query some online resource.

I think that this could be a right place https://github.com/geopandas/contextily/blob/main/contextily/tile.py#L374 (but there may be more).

Contributions are welcome :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants