From 2082a3c1adfc97d77606bd69b18361a27323aef5 Mon Sep 17 00:00:00 2001 From: kthui <18255193+kthui@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:54:43 -0800 Subject: [PATCH 1/2] fix: Hold GIL when deleting numpy array --- src/pb_tensor.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pb_tensor.cc b/src/pb_tensor.cc index 1ab95144..9fde62fe 100644 --- a/src/pb_tensor.cc +++ b/src/pb_tensor.cc @@ -503,6 +503,14 @@ PbTensor::~PbTensor() noexcept(false) { pb_memory_.reset(); DeleteDLPack(); + +#ifdef TRITON_PB_STUB + { + py::gil_scoped_acquire acquire; + py::array numpy_array_local(std::move(numpy_array_)); + py::array numpy_array_serialized_local(std::move(numpy_array_serialized_)); + } +#endif } const std::string& From d053a3dfcea067f3acc1f3c55602fef37797062b Mon Sep 17 00:00:00 2001 From: kthui <18255193+kthui@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:59:26 -0800 Subject: [PATCH 2/2] chore: setting py obj to None may not destruct the object --- src/pb_stub.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pb_stub.cc b/src/pb_stub.cc index a26719d2..51df5aa2 100644 --- a/src/pb_stub.cc +++ b/src/pb_stub.cc @@ -1032,9 +1032,9 @@ Stub::~Stub() { py::gil_scoped_acquire acquire; - async_event_loop_ = py::none(); - background_futures_ = py::none(); - model_instance_ = py::none(); + py::object async_event_loop_local(std::move(async_event_loop_)); + py::object background_futures_local(std::move(background_futures_)); + py::object model_instance_local(std::move(model_instance_)); } stub_instance_.reset(); stub_message_queue_.reset();