{"record":{"id":"830263b3ed9dbc88","repo":"pola-rs/polars","slug":"gevent-is-required-for-using-lazyframe-collect-asy","errorCode":null,"errorMessage":"gevent is required for using LazyFrame.collect_async(gevent=True) orpolars.collect_all_async(gevent=True)","messagePattern":"gevent is required for using LazyFrame\\.collect_async\\(gevent=True\\) orpolars\\.collect_all_async\\(gevent=True\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/async_.py","lineNumber":29,"sourceCode":"    from collections.abc import Generator\n\n    from polars import DataFrame\n    from polars._plr import PyDataFrame\n\n\nT = TypeVar(\"T\")\n\n\nclass _GeventDataFrameResult(Generic[T]):\n    __slots__ = (\"_result\", \"_value\", \"_watcher\")\n\n    def __init__(self) -> None:\n        if not _GEVENT_AVAILABLE:\n            msg = (\n                \"gevent is required for using LazyFrame.collect_async(gevent=True) or\"\n                \"polars.collect_all_async(gevent=True)\"\n            )\n            raise ImportError(msg)\n\n        from gevent.event import AsyncResult  # type: ignore[import-untyped]\n        from gevent.hub import get_hub  # type: ignore[import-untyped]\n\n        self._value: None | Exception | PyDataFrame | list[PyDataFrame] = None\n        self._result = AsyncResult()\n\n        self._watcher = get_hub().loop.async_()\n        self._watcher.start(self._watcher_callback)\n\n    def get(\n        self,\n        block: bool = True,  # noqa: FBT001\n        timeout: float | int | None = None,\n    ) -> T:\n        return self.result.get(block=block, timeout=timeout)\n\n    @property","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/_utils/async_.py#L11-L47","documentation":"LazyFrame.collect_async(gevent=True) and polars.collect_all_async(gevent=True) integrate with gevent's hub via an async watcher; that integration requires the gevent package, whose availability polars determined when polars._utils.async_ was imported. This ImportError is raised in _GeventDataFrameResult.__init__ the moment gevent integration is requested but gevent is absent.","triggerScenarios":"Calling `lf.collect_async(gevent=True)` or `pl.collect_all_async(lazy_frames, gevent=True)` in an interpreter where gevent is not installed — e.g. running code normally deployed under gunicorn+gevent workers in a plain dev shell or test runner.","commonSituations":"Production uses gunicorn[gevent] so gevent is present in prod but missing in dev/CI; requirements split so the web extra never reaches data-processing code paths; unit tests exercising async collect outside the gevent environment.","solutions":["Install gevent: `pip install gevent` (and add it to the deployment requirements)","Or drop `gevent=True` and use the default asyncio-based collect_async behavior","If tests don't need gevent semantics, parametrize the flag so tests run the asyncio path and only gunicorn runs gevent=True"],"exampleFix":"# before\nres = lf.collect_async(gesture=False, gevent=True)  # ImportError: gevent is required ...\n\n# after\n# pip install gevent\nres = lf.collect_async(gevent=True)\n# or, without gevent:\nres = lf.collect_async()  # asyncio-based","handlingStrategy":"validation","validationCode":"import importlib.util\n\nif not importlib.util.find_spec(\"gevent\"):\n    # fall back to the default asyncio-based API instead of failing\ndef collect(lf):\n    return lf.collect_async() if importlib.util.find_spec(\"gevent\") is None else lf.collect_async(gevent=True)","typeGuard":"import importlib.util\n\ndef gevent_available() -> bool:\n    return importlib.util.find_spec(\"gevent\") is not None","tryCatchPattern":"try:\n    result = lf.collect_async(gevent=True)\nexcept ImportError as e:\n    if \"gevent\" not in str(e):\n        raise\n    result = lf.collect_async()  # asyncio fallback","preventionTips":["Add gevent to the same requirements as your gunicorn gevent worker config","Feature-flag the gevent path and default to asyncio in dev/test environments","Check importlib.util.find_spec('gevent') before requesting gevent=True"],"tags":["dependencies","async","gevent","optional-deps"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}