@@ -15,7 +15,7 @@ from typing import TypeVar, Union
1515
1616from cuda.core.experimental._dlpack import DLDeviceType, make_py_capsule
1717from cuda.core.experimental._stream import Stream, default_stream
18- from cuda.core.experimental._utils.cuda_utils import driver
18+ from cuda.core.experimental._utils.cuda_utils import driver, is_shutting_down
1919
2020# TODO: define a memory property mixin class and make Buffer and
2121# MemoryResource both inherit from it
@@ -59,7 +59,7 @@ cdef class Buffer:
5959 def __del__ (self ):
6060 self .close()
6161
62- cpdef close(self , stream: Stream = None ):
62+ cpdef close(self , stream: Stream = None , is_shutting_down = is_shutting_down ):
6363 """ Deallocate this buffer asynchronously on the given stream.
6464
6565 This buffer is released back to their memory resource
@@ -72,7 +72,8 @@ cdef class Buffer:
7272 the behavior depends on the underlying memory resource.
7373 """
7474 if self ._ptr and self ._mr is not None :
75- self ._mr.deallocate(self ._ptr, self ._size, stream)
75+ if not is_shutting_down():
76+ self ._mr.deallocate(self ._ptr, self ._size, stream)
7677 self ._ptr = 0
7778 self ._mr = None
7879 self ._ptr_obj = None
0 commit comments