Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/python_be.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,32 @@ TRITONBACKEND_ModelInstanceExecute(
return nullptr;
}

TRITONBACKEND_ISPEC TRITONSERVER_Error*
TRITONBACKEND_ModelInstanceReady(TRITONBACKEND_ModelInstance* instance)
{
void* vstate;
RETURN_IF_ERROR(TRITONBACKEND_ModelInstanceState(instance, &vstate));
ModelInstanceState* instance_state =
reinterpret_cast<ModelInstanceState*>(vstate);

if (!instance_state->Stub()->StubActive()) {
return TRITONSERVER_ErrorNew(
TRITONSERVER_ERROR_INTERNAL, (std::string("Stub process '") +
instance_state->Name() + "' is not alive")
.c_str());
}

if (!instance_state->IsStubProcessAlive()) {
return TRITONSERVER_ErrorNew(
TRITONSERVER_ERROR_INTERNAL,
(std::string("Stub process '") + instance_state->Name() +
"' is not healthy (unresponsive).")
.c_str());
}

return nullptr;
}

TRITONBACKEND_ISPEC TRITONSERVER_Error*
TRITONBACKEND_ModelInstanceFinalize(TRITONBACKEND_ModelInstance* instance)
{
Expand Down
27 changes: 23 additions & 4 deletions src/stub_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,24 @@ StubLauncher::StubActive()
GetExitCodeProcess(stub_pid_.hProcess, &ec);
return (ec == STILL_ACTIVE);
#else
return (stub_pid_ != 0);
if (stub_pid_ == 0) {
return false;
}

int status;
pid_t return_pid = waitpid(stub_pid_, &status, WNOHANG);
if (return_pid == -1) {
// If waitpid fails, it likely means the process no longer exists (ECHILD)
stub_pid_ = 0;
return false;
} else if (return_pid == stub_pid_) {
// Process has exited and has been reaped
stub_pid_ = 0;
return false;
}

// return_pid == 0 means the process is still running
return true;
#endif
}

Expand Down Expand Up @@ -824,9 +841,11 @@ StubLauncher::KillStubProcess()
CloseHandle(stub_pid_.hProcess);
CloseHandle(stub_pid_.hThread);
#else
kill(stub_pid_, SIGKILL);
WaitForStubProcess();
stub_pid_ = 0;
if (stub_pid_ != 0) {
kill(stub_pid_, SIGKILL);
WaitForStubProcess();
stub_pid_ = 0;
}
#endif
}

Expand Down
Loading