Skip to content

Don't use a global geos context handle #31

@jorisvandenbossche

Description

@jorisvandenbossche

Currently a global handle is defined:

https://github.com/caspervdw/pygeos/blob/de5ed5c5f0a55bf471531e328d1a1b0476bcafd2/src/ufuncs.c#L1206-L1211

However, if you want to use pygeos in multiple threads (when releasing the GIL, https://github.com/caspervdw/pygeos/issues/7), I think we need a context per thread.

In the cython branch of geopandas, we had a context manager to create and destroy a thread:

https://github.com/geopandas/geopandas/blob/e92536340fd7f1ed92925b960226ab10adb37717/geopandas/vectorized.pyx#L1270-L1278

which was then used in each vectorized function (here the ufuncs) around the code that called into GEOS.

I suppose we will need something similar here, although not sure what the best way would be (since the ufuncs are templated, just creating in the beginning / destroying at the end might be not too much duplication).

The version in pygeos also sets the error message handler, which we didn't do in the cython version. Is that for converting geos errors into python errors? (and does that work how it is currently coded? Shapely wraps some logging functionality with it)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions