File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77 :license: MIT, see LICENSE for more details.
88"""
99
10+ import weakref
1011from .geodifflib import GeoDiffLib
1112
1213
@@ -15,6 +16,9 @@ class GeoDiff:
1516 geodiff is a module to create and apply changesets to GIS files (geopackage)
1617 """
1718
19+ # Dictionary of libname to instance of GeoDiffLib
20+ _clib_cache = weakref .WeakValueDictionary ()
21+
1822 def __init__ (self , libname = None ):
1923 """
2024 if libname is None, it tries to import c-extension from wheel
@@ -33,7 +37,11 @@ def __del__(self):
3337
3438 def _lazy_load (self ):
3539 if self .clib is None :
36- self .clib = GeoDiffLib (self .libname )
40+ if clib := GeoDiff ._clib_cache .get (self .libname ):
41+ self .clib = clib
42+ else :
43+ self .clib = GeoDiffLib (self .libname )
44+ GeoDiff ._clib_cache [self .libname ] = self .clib
3745
3846 if self .context is None :
3947 self .context = self .clib .create_context ()
@@ -43,8 +51,6 @@ def shutdown(self):
4351 self .clib .destroy_context (self .context )
4452 self .context = None
4553
46- if self .clib is not None :
47- self .clib .shutdown ()
4854 self .clib = None
4955 self .callbackLogger = None
5056
You can’t perform that action at this time.
0 commit comments