-
Notifications
You must be signed in to change notification settings - Fork 216
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
REF: Making pyproj completely threadsafe #782
Comments
This kills making the pyproj objects thread safe: OSGeo/PROJ#1047 Seems the Since this is the case, |
Just had another thought, The Following the logic in geopandas/geopandas#1846, Instead of having the Python class CRSLocal(threading.local):
def __init__(self):
self._crs = None # Initialises in each thread
class CRS:
self._local = CRSLocal()
... Then it could use the @property
def _local_crs(self):
if self._local._crs is None:
self._local._crs = _CRS(self.srs)
return self._local._crs A similar concept could be applied to the |
Indeed, that's what I tried to suggest in geopandas/geopandas#1842 (comment) ;) It might be require quite some changes in pyproj to do this, but on the other hand, would avoid similar changes in every package using pyproj. |
I guess that you were one step ahead of me. I was stuck on another design and missed that. Glad we're on the same page now 😂 |
@jorisvandenbossche since you had the idea first, you have first dibs on implementing this. Is this something you would like to take a stab at? (no worries if you would like to pass on that) |
"Would like" in theory yes ;) |
Sounds good. PR reviews and testing will be much appreciated 👍 |
Still some classes that aren't: |
pyproj CRS/Proj/Transformer objects aren't meant to be shared across threads, but they can exist if created within the thread (ref). Sharing the same object across threads can cause issues (#589, corteva/geocube#41)
The only way to entirely solve this is to be able to have a single PROJ context per thread and to be able to dynamically switch to that context depending on the thread they are in.
Current concerns to overcome:
threading.local
object is a possibility. However it may require transitioning from cython to python to cython types. This has caused stability issues in the past (PROJ 6.2+ required; remove global context; autoclose database #412), so need to be careful.PJ *
objects have a context assigned at creation. Would need to useproj_assign_context
each time you use the context object.The text was updated successfully, but these errors were encountered: