Skip to content

Commit fad31cc

Browse files
Handle error in async_dec_ref: decrement ref counts and wait for the job to complete
1 parent f60face commit fad31cc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

dpctl/_sycl_queue.pyx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import ctypes
6565
from .enum_types import backend_type
6666

6767
from cpython cimport pycapsule
68-
from cpython.ref cimport Py_INCREF, PyObject
68+
from cpython.ref cimport Py_DECREF, Py_INCREF, PyObject
6969
from libc.stdlib cimport free, malloc
7070

7171
import collections.abc
@@ -835,7 +835,13 @@ cdef class SyclQueue(_SyclQueue):
835835
Py_INCREF(<object> arg_objects[i])
836836

837837
# schedule decrement
838-
async_dec_ref(self.get_queue_ref(), arg_objects, len(args), &Eref, 1)
838+
if async_dec_ref(self.get_queue_ref(), arg_objects, len(args), &Eref, 1):
839+
# async task submission failed, decrement ref counts and wait
840+
for i in range(len(args)):
841+
arg_objects[i] = <PyObject *>(args[i])
842+
Py_DECREF(<object> arg_objects[i])
843+
with nogil: DPCTLEvent_Wait(Eref)
844+
839845
# free memory
840846
free(arg_objects)
841847

0 commit comments

Comments
 (0)