@@ -9,7 +9,6 @@ from cuda.core.experimental._utils.cuda_utils cimport (
99 _check_driver_error as raise_if_driver_error,
1010 check_or_create_options,
1111)
12- import sys
1312
1413from dataclasses import dataclass
1514from typing import Optional, TypeVar, Union, TYPE_CHECKING
@@ -20,7 +19,6 @@ import cython
2019import multiprocessing
2120import os
2221import platform
23- import sys
2422import weakref
2523from cuda.core.experimental._dlpack import DLDeviceType, make_py_capsule
2624from cuda.core.experimental._stream import Stream, default_stream
@@ -72,17 +70,8 @@ cdef class Buffer:
7270 self ._mr = mr
7371 return self
7472
75- def __del__ (self ):
76- self ._shutdown_safe_close()
77-
78- cdef _shutdown_safe_close(self , stream: Stream = None , is_shutting_down = sys.is_finalizing):
79- if is_shutting_down and is_shutting_down():
80- return
81- if self ._ptr and self ._mr is not None :
82- self ._mr.deallocate(self ._ptr, self ._size, stream)
83- self ._ptr = 0
84- self ._mr = None
85- self ._ptr_obj = None
73+ def __dealloc__ (self ):
74+ self .close()
8675
8776 def __reduce__ (self ):
8877 return Buffer.from_ipc_descriptor, (self .memory_resource, self .get_ipc_descriptor())
@@ -99,7 +88,11 @@ cdef class Buffer:
9988 The stream object to use for asynchronous deallocation. If None,
10089 the behavior depends on the underlying memory resource.
10190 """
102- self ._shutdown_safe_close(stream, is_shutting_down = None )
91+ if self ._ptr and self ._mr is not None :
92+ self ._mr.deallocate(self ._ptr, self ._size, stream)
93+ self ._ptr = 0
94+ self ._mr = None
95+ self ._ptr_obj = None
10396
10497 @property
10598 def handle (self ) -> DevicePointerT:
@@ -424,8 +417,7 @@ cdef class IPCAllocationHandle:
424417 self ._handle = - 1
425418 self ._uuid = None
426419
427- def __del__ (self ):
428- """ Close the handle."""
420+ def __dealloc__ (self ):
429421 self .close()
430422
431423 def __int__ (self ) -> int:
0 commit comments