File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
Expand file tree Collapse file tree 1 file changed +10
-3
lines changed 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,12 @@ def __del__(self):
3337
3438 def _lazy_load (self ):
3539 if self .clib is None :
36- self .clib = GeoDiffLib (self .libname )
40+ clib = GeoDiff ._clib_cache .get (self .libname )
41+ if clib :
42+ self .clib = clib
43+ else :
44+ self .clib = GeoDiffLib (self .libname )
45+ GeoDiff ._clib_cache [self .libname ] = self .clib
3746
3847 if self .context is None :
3948 self .context = self .clib .create_context ()
@@ -43,8 +52,6 @@ def shutdown(self):
4352 self .clib .destroy_context (self .context )
4453 self .context = None
4554
46- if self .clib is not None :
47- self .clib .shutdown ()
4855 self .clib = None
4956 self .callbackLogger = None
5057
You can’t perform that action at this time.
0 commit comments