Use weakref in _HdfsFileNanny to avoid cyclic gc

Change-Id: I9f2b03e3f9e8677c89f144ff890edc3900431a40
This commit is contained in:
Wes McKinney committed 2016-12-08 16:42:01 -05:00
1 parent 274d0c5e8e
commit 3a8e641ede
1 file changed
+10 -5
+10 -5
View File
@@ -564,16 +564,19 @@ cdef class HdfsClient:
cdef class _HdfsFileNanny:
cdef:
object client
object file_handle
object file_handle_ref
def __cinit__(self, client, file_handle):
import weakref
self.client = client
self.file_handle = file_handle
self.file_handle_ref = weakref.ref(file_handle)
def __dealloc__(self):
self.file_handle.close()
# try to avoid cyclic GC
self.file_handle = None
fh = self.file_handle_ref()
if fh:
fh.close()
# avoid cyclic GC
self.file_handle_ref = None
self.client = None
@@ -583,6 +586,8 @@ cdef class HdfsFile(NativeFile):
object mode
object parent
cdef object __weakref__
def __dealloc__(self):
self.parent = None