@@ -70,12 +70,16 @@ cdef class Buffer:
7070 return self
7171
7272 def __del__ (self ):
73- self .safe_close ()
73+ self ._shutdown_safe_close ()
7474
75- cpdef safe_close(self , stream: Stream = None , is_shutting_down = sys.is_finalizing):
75+ cdef _shutdown_safe_close(self , stream: Stream = None , is_shutting_down = sys.is_finalizing):
76+ if is_shutting_down and is_shutting_down():
77+ return
7678 if self ._ptr and self ._mr is not None :
77- if not is_shutting_down():
78- self ._mr.deallocate(self ._ptr, self ._size, stream)
79+ self ._mr.deallocate(self ._ptr, self ._size, stream)
80+ self ._ptr = 0
81+ self ._mr = None
82+ self ._ptr_obj = None
7983
8084 cpdef close(self , stream: Stream = None ):
8185 """ Deallocate this buffer asynchronously on the given stream.
@@ -89,11 +93,7 @@ cdef class Buffer:
8993 The stream object to use for asynchronous deallocation. If None,
9094 the behavior depends on the underlying memory resource.
9195 """
92- if self ._ptr and self ._mr is not None :
93- self ._mr.deallocate(self ._ptr, self ._size, stream)
94- self ._ptr = 0
95- self ._mr = None
96- self ._ptr_obj = None
96+ self ._shutdown_safe_close(stream, is_shutting_down = None )
9797
9898 @property
9999 def handle (self ) -> DevicePointerT:
0 commit comments