python: shared library can be unloaded from under our feet. issue reported by @joelpx

This commit is contained in:
Nguyen Anh Quynh 2015-06-04 11:36:56 +08:00
parent e42aaffb8d
commit 8ac478bd4b
1 changed files with 7 additions and 4 deletions

View File

@ -692,10 +692,13 @@ class Cs(object):
# destructor to be called automatically when object is destroyed.
def __del__(self):
if self.csh and _cs is not None:
status = _cs.cs_close(ctypes.byref(self.csh))
if status != CS_ERR_OK:
raise CsError(status)
if self.csh:
try:
status = _cs.cs_close(ctypes.byref(self.csh))
if status != CS_ERR_OK:
raise CsError(status)
except: # _cs might be pulled from under our feet
pass
# def option(self, opt_type, opt_value):