diff --git a/dpctl/_host_task_util.hpp b/dpctl/_host_task_util.hpp index 5208e11d2c..7871cdebfc 100644 --- a/dpctl/_host_task_util.hpp +++ b/dpctl/_host_task_util.hpp @@ -55,7 +55,8 @@ int async_dec_ref(DPCTLSyclQueueRef QRef, *(reinterpret_cast(ERefs[ev_id]))); } cgh.host_task([obj_array_size, obj_vec]() { - { + // if the main thread has not finilized the interpreter yet + if (Py_IsInitialized()) { PyGILState_STATE gstate; gstate = PyGILState_Ensure(); for (size_t i = 0; i < obj_array_size; ++i) {