Fixed #25657 -- Ignored exceptions when destroying geometry objects
Due to randomness of garbage collection with geometry objects, it's easier to simply ignore AttributeError/TypeError generally raised when parts of objects are already garbage-collected. Thanks Sergey Fedoseev and Tim Graham for reviewing the patch.
This commit is contained in:
parent
ec708803f7
commit
cd40d9e721
|
@ -87,8 +87,10 @@ class DataSource(GDALBase):
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"Destroys this DataStructure object."
|
"Destroys this DataStructure object."
|
||||||
if self._ptr and capi:
|
try:
|
||||||
capi.destroy_ds(self._ptr)
|
capi.destroy_ds(self._ptr)
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
pass # Some part might already have been garbage collected
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
"Allows for iteration over the layers in a data source."
|
"Allows for iteration over the layers in a data source."
|
||||||
|
|
|
@ -29,8 +29,10 @@ class Feature(GDALBase):
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"Releases a reference to this object."
|
"Releases a reference to this object."
|
||||||
if self._ptr and capi:
|
try:
|
||||||
capi.destroy_feature(self._ptr)
|
capi.destroy_feature(self._ptr)
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
pass # Some part might already have been garbage collected
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -121,8 +121,10 @@ class OGRGeometry(GDALBase):
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"Deletes this Geometry."
|
"Deletes this Geometry."
|
||||||
if self._ptr and capi:
|
try:
|
||||||
capi.destroy_geom(self._ptr)
|
capi.destroy_geom(self._ptr)
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
pass # Some part might already have been garbage collected
|
||||||
|
|
||||||
# Pickle routines
|
# Pickle routines
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
|
|
|
@ -131,8 +131,10 @@ class GDALRaster(GDALBase):
|
||||||
raise GDALException('Invalid data source input type: "{}".'.format(type(ds_input)))
|
raise GDALException('Invalid data source input type: "{}".'.format(type(ds_input)))
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self._ptr and capi:
|
try:
|
||||||
capi.close_ds(self._ptr)
|
capi.close_ds(self._ptr)
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
pass # Some part might already have been garbage collected
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
|
@ -96,8 +96,10 @@ class SpatialReference(GDALBase):
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"Destroys this spatial reference."
|
"Destroys this spatial reference."
|
||||||
if self._ptr and capi:
|
try:
|
||||||
capi.release_srs(self._ptr)
|
capi.release_srs(self._ptr)
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
pass # Some part might already have been garbage collected
|
||||||
|
|
||||||
def __getitem__(self, target):
|
def __getitem__(self, target):
|
||||||
"""
|
"""
|
||||||
|
@ -341,8 +343,10 @@ class CoordTransform(GDALBase):
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"Deletes this Coordinate Transformation object."
|
"Deletes this Coordinate Transformation object."
|
||||||
if self._ptr and capi:
|
try:
|
||||||
capi.destroy_ct(self._ptr)
|
capi.destroy_ct(self._ptr)
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
pass
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'Transform from "%s" to "%s"' % (self._srs1_name, self._srs2_name)
|
return 'Transform from "%s" to "%s"' % (self._srs1_name, self._srs2_name)
|
||||||
|
|
|
@ -123,8 +123,10 @@ class GEOSGeometry(GEOSBase, ListMixin):
|
||||||
Destroys this Geometry; in other words, frees the memory used by the
|
Destroys this Geometry; in other words, frees the memory used by the
|
||||||
GEOS C++ object.
|
GEOS C++ object.
|
||||||
"""
|
"""
|
||||||
if self._ptr and capi:
|
try:
|
||||||
capi.destroy_geom(self._ptr)
|
capi.destroy_geom(self._ptr)
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
pass # Some part might already have been garbage collected
|
||||||
|
|
||||||
def __copy__(self):
|
def __copy__(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -21,8 +21,10 @@ class PreparedGeometry(GEOSBase):
|
||||||
self.ptr = capi.geos_prepare(geom.ptr)
|
self.ptr = capi.geos_prepare(geom.ptr)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self._ptr and capi:
|
try:
|
||||||
capi.prepared_destroy(self._ptr)
|
capi.prepared_destroy(self._ptr)
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
pass # Some part might already have been garbage collected
|
||||||
|
|
||||||
def contains(self, other):
|
def contains(self, other):
|
||||||
return capi.prepared_contains(self.ptr, other.ptr)
|
return capi.prepared_contains(self.ptr, other.ptr)
|
||||||
|
|
|
@ -120,8 +120,10 @@ class IOBase(GEOSBase):
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
# Cleaning up with the appropriate destructor.
|
# Cleaning up with the appropriate destructor.
|
||||||
if self._ptr:
|
try:
|
||||||
self._destructor(self._ptr)
|
self._destructor(self._ptr)
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
pass # Some part might already have been garbage collected
|
||||||
|
|
||||||
# ### Base WKB/WKT Reading and Writing objects ###
|
# ### Base WKB/WKT Reading and Writing objects ###
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue