[Python] fastapi workers die in add_basemap

Discussão em 'Python' iniciado por Stack, Julho 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have a problem with add_basemap from contextily. (I'm new to this to be honest)

    I use fastapi in docker with workers=4, and contextily to make images. In random time it die add_basemap (I don't know why), in logs i can see

    fastapi-1 | 2025-07-29 11:40:16,934 - logs_storage.logs_storage - INFO - Saving summary image
    fastapi-1 | 2025-07-29 11:40:26,967 - logs_uploader.save_image - WARNING - Adding basemaps timed out after 10 seconds — proceeding without them.
    fastapi-1 | INFO: Waiting for child process [361]
    fastapi-1 | INFO: Child process [361] died


    I thought that signal will help me, but it didn't

    class TimeoutException(Exception):
    pass

    def _timeout_handler(signum: int, frame) -> None:
    raise TimeoutException("Timeout while adding basemap")


    signal.signal(signal.SIGALRM, _timeout_handler)
    signal.alarm(ADD_BASEMAP_TIMEOUT)
    try:
    ctx.add_basemap(ax, source=ctx.providers.Esri.WorldImagery, crs="EPSG:3857", alpha=1.0) # pyright: ignore
    ctx.add_basemap(ax, source=ctx.providers.CartoDB.PositronOnlyLabels, crs="EPSG:3857", alpha=0.95) # pyright: ignore
    _LOGGER.info("Basemaps added successfully")
    except TimeoutException:
    _LOGGER.warning(f"Adding basemaps timed out after {ADD_BASEMAP_TIMEOUT} seconds — proceeding without them.")
    except Exception as e:
    _LOGGER.warning(f"Error adding basemap: {e}")
    finally:
    signal.alarm(0)


    I also try ThreadPoolExecutor, but it also doesn't work

    Continue reading...

Compartilhe esta Página