Skip to content

Commit 7347d77

Browse files
Add shutdown detection to ObjectRef __del__ method.
On older Pythons (<3.4) the shutdown sequence sets globals etc to None to help gc. This means that the calling of a global as part of `__del__` as occurs in `ffi::ObjectRef` leads to error messages like: `Exception TypeError: "'NoneType' object is not callable" in...` Using the already existing shutdown detection mechanism in the `__del__` it's possible to avoid calling the global and as a result stops these message/calling None. The LLVM object will leak either way, at least this way is leaks quietly. Fixes #350 Fixes numba/numba#2818
1 parent 80d8f86 commit 7347d77

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

llvmlite/binding/ffi.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ def __del__(self, _is_shutting_down=_is_shutting_down):
165165
# Avoid errors trying to rely on globals and modules at interpreter
166166
# shutdown.
167167
if not _is_shutting_down():
168-
self.close()
168+
if self.close is not None:
169+
self.close()
169170

170171
def __str__(self):
171172
if self._ptr is None:
@@ -239,9 +240,10 @@ def __enter__(self):
239240
def __exit__(self, exc_type, exc_val, exc_tb):
240241
self.close()
241242

242-
def __del__(self):
243-
if self.close is not None:
244-
self.close()
243+
def __del__(self, _is_shutting_down=_is_shutting_down):
244+
if not _is_shutting_down():
245+
if self.close is not None:
246+
self.close()
245247

246248
def __bool__(self):
247249
return bool(self._ptr)

0 commit comments

Comments
 (0)