Skip to content

Commit efe7fe0

Browse files
committed
use __dealloc__ in event/stream
1 parent 2c86825 commit efe7fe0

3 files changed

Lines changed: 11 additions & 27 deletions

File tree

cuda_core/cuda/core/experimental/_event.pxd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ cdef class Event:
1010
int _device_id
1111
object _ctx_handle
1212

13-
cdef _shutdown_safe_close(self, is_shutting_down=*)
1413
cpdef close(self)

cuda_core/cuda/core/experimental/_event.pyx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ from cuda.core.experimental._context import Context
2020
from cuda.core.experimental._utils.cuda_utils import (
2121
CUDAError,
2222
driver,
23-
handle_return,
2423
)
25-
import sys
2624
if TYPE_CHECKING:
2725
import cuda.bindings
2826
from cuda.core.experimental._device import Device
@@ -108,20 +106,15 @@ cdef class Event:
108106
self._ctx_handle = ctx_handle
109107
return self
110108

111-
cdef _shutdown_safe_close(self, is_shutting_down=sys.is_finalizing):
112-
if is_shutting_down and is_shutting_down():
113-
return
109+
cpdef close(self):
110+
"""Destroy the event."""
114111
if self._handle != NULL:
115112
with nogil:
116113
HANDLE_RETURN(cydriver.cuEventDestroy(self._handle))
117114
self._handle = <cydriver.CUevent>(NULL)
118115

119-
cpdef close(self):
120-
"""Destroy the event."""
121-
self._shutdown_safe_close(is_shutting_down=None)
122-
123-
def __del__(self):
124-
self._shutdown_safe_close()
116+
def __dealloc__(self):
117+
self.close()
125118

126119
def __isub__(self, other):
127120
return NotImplemented

cuda_core/cuda/core/experimental/_stream.pyx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ from cuda.core.experimental._utils.cuda_utils cimport (
1414
HANDLE_RETURN,
1515
)
1616

17-
import sys
18-
1917
import cython
2018
import os
2119
import warnings
@@ -202,12 +200,15 @@ cdef class Stream:
202200
return self
203201

204202
def __del__(self):
205-
self._shutdown_safe_close()
203+
self.close()
204+
205+
cpdef close(self):
206+
"""Destroy the stream.
206207
207-
cdef _shutdown_safe_close(self, is_shutting_down=sys.is_finalizing):
208-
if is_shutting_down and is_shutting_down():
209-
return
208+
Destroy the stream if we own it. Borrowed foreign stream
209+
object will instead have their references released.
210210
211+
"""
211212
if self._owner is None:
212213
if self._handle and not self._builtin:
213214
with nogil:
@@ -216,15 +217,6 @@ cdef class Stream:
216217
self._owner = None
217218
self._handle = <cydriver.CUstream>(NULL)
218219

219-
cpdef close(self):
220-
"""Destroy the stream.
221-
222-
Destroy the stream if we own it. Borrowed foreign stream
223-
object will instead have their references released.
224-
225-
"""
226-
self._shutdown_safe_close(is_shutting_down=None)
227-
228220
def __cuda_stream__(self) -> tuple[int, int]:
229221
"""Return an instance of a __cuda_stream__ protocol."""
230222
return (0, int(self.handle))

0 commit comments

Comments
 (0)