diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py index 2e8d3d6ec8..5641b6ac42 100644 --- a/bindings/python/capstone/__init__.py +++ b/bindings/python/capstone/__init__.py @@ -692,10 +692,13 @@ def __init__(self, arch, mode): # 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):