Skip to content

Commit a26c928

Browse files
committed
Update
1 parent 4fdb468 commit a26c928

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/pb_stub.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,11 +1040,13 @@ Stub::~Stub()
10401040
{
10411041
#ifdef TRITON_ENABLE_GPU
10421042
try {
1043-
CUDAHandler& cuda_api = CUDAHandler::getInstance();
1044-
for (auto& m :
1045-
shm_pool_->GetCUDAMemoryPoolManager()->CUDAPoolAddressMap()) {
1046-
if (m.second != nullptr) {
1047-
cuda_api.CloseCudaHandle(m.first, m.second);
1043+
if (shm_pool_ != nullptr) {
1044+
CUDAHandler& cuda_api = CUDAHandler::getInstance();
1045+
for (auto& m :
1046+
shm_pool_->GetCUDAMemoryPoolManager()->CUDAPoolAddressMap()) {
1047+
if (m.second != nullptr) {
1048+
cuda_api.CloseCudaHandle(m.first, m.second);
1049+
}
10481050
}
10491051
}
10501052
}
@@ -1053,13 +1055,14 @@ Stub::~Stub()
10531055
}
10541056
#endif
10551057

1056-
{
1058+
// Ensure the interpreter is active before trying to clean up.
1059+
if (Py_IsInitialized()) {
10571060
py::gil_scoped_acquire acquire;
10581061
py::object async_event_loop_local(std::move(async_event_loop_));
10591062
py::object background_futures_local(std::move(background_futures_));
10601063
py::object model_instance_local(std::move(model_instance_));
10611064
}
1062-
stub_instance_.reset();
1065+
10631066
stub_message_queue_.reset();
10641067
parent_message_queue_.reset();
10651068
stub_to_parent_mq_.reset();
@@ -2030,6 +2033,7 @@ main(int argc, char** argv)
20302033
catch (const PythonBackendException& pb_exception) {
20312034
LOG_INFO << "Failed to preinitialize Python stub: " << pb_exception.what();
20322035
logger.reset();
2036+
stub.reset();
20332037
exit(1);
20342038
}
20352039

src/stub_launcher.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ StubLauncher::Launch()
315315
}
316316

317317
if (stub_process_kind_ == "AUTOCOMPLETE_STUB") {
318-
THROW_IF_BACKEND_MODEL_ERROR(err);
318+
if (err != nullptr) {
319+
throw BackendModelException(err);
320+
}
319321
try {
320322
AutocompleteStubProcess();
321323
}
@@ -485,7 +487,9 @@ StubLauncher::Launch()
485487
}
486488

487489
if (stub_process_kind_ == "AUTOCOMPLETE_STUB") {
488-
THROW_IF_BACKEND_MODEL_ERROR(err);
490+
if (err != nullptr) {
491+
throw BackendModelException(err);
492+
}
489493
try {
490494
AutocompleteStubProcess();
491495
}

0 commit comments

Comments
 (0)