Make __del__ method idempotent (#2627)

Addresses Issue #2533.
This commit is contained in:
Philip Cho 2017-09-27 00:03:55 -07:00 committed by Yuan (Terry) Tang
parent 8d15024ac7
commit 31ad40b963

View File

@ -363,7 +363,9 @@ class DMatrix(object):
nthread))
def __del__(self):
_check_call(_LIB.XGDMatrixFree(self.handle))
if self.handle is not None:
_check_call(_LIB.XGDMatrixFree(self.handle))
self.handle = None
def get_float_info(self, field):
"""Get float property from the DMatrix.
@ -738,7 +740,9 @@ class Booster(object):
self.load_model(model_file)
def __del__(self):
_LIB.XGBoosterFree(self.handle)
if self.handle is not None:
_check_call(_LIB.XGBoosterFree(self.handle))
self.handle = None
def __getstate__(self):
# can't pickle ctypes pointers