File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed
Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 77 :license: MIT, see LICENSE for more details.
88"""
99
10- from .main import GeoDiff
10+ from .main import GeoDiff , shutdown
1111from .geodifflib import (
1212 GeoDiffLibError ,
1313 GeoDiffLibConflictError ,
2020
2121__all__ = [
2222 "GeoDiff" ,
23+ "shutdown" ,
2324 "GeoDiffLibError" ,
2425 "GeoDiffLibConflictError" ,
2526 "GeoDiffLibUnsupportedChangeError" ,
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ def _lazy_load(self):
5555 self .context = self .clib .create_context ()
5656
5757 def shutdown (self ):
58- if self .context is not None :
58+ if self .context is not None and self . clib . lib is not None :
5959 self .clib .destroy_context (self .context )
6060 self .context = None
6161
@@ -469,3 +469,12 @@ def create_wkb_from_gpkg_header(self, geometry):
469469 """
470470 self ._lazy_load ()
471471 return self .clib .create_wkb_from_gpkg_header (self .context , geometry )
472+
473+ def shutdown ():
474+ """
475+ Unloads global GeoDiffLib instance. This breaks all existing GeoDiff
476+ instances!
477+ """
478+ if GeoDiff ._clib_weakref is not None and GeoDiff ._clib_weakref () is not None :
479+ GeoDiff ._clib_weakref ().shutdown ()
480+ GeoDiff ._clib_weakref = None
Original file line number Diff line number Diff line change 66
77import unittest
88
9- from pygeodiff import GeoDiff
9+ from pygeodiff import GeoDiff , GeoDiffLibError , shutdown
1010
1111
1212class UnitTestsLibLazyloading (unittest .TestCase ):
@@ -41,3 +41,12 @@ def test_multiple(self):
4141 self .assertIsNotNone (GeoDiff ._clib_weakref ())
4242 del geodiff2
4343 self .assertIsNone (GeoDiff ._clib_weakref ())
44+
45+ def test_global_shutdown (self ):
46+ geodiff = GeoDiff ()
47+ geodiff .version ()
48+ self .assertIsNotNone (GeoDiff ._clib_weakref )
49+ self .assertIsNotNone (GeoDiff ._clib_weakref ())
50+ shutdown ()
51+ self .assertIsNone (GeoDiff ._clib_weakref )
52+ self .assertRaises (AttributeError , geodiff .version )
You can’t perform that action at this time.
0 commit comments