Skip to content

Commit

Permalink
[DO NOT MERGE] Revert "[DO NOT MERGE] Revert "Restructure cleaning up…
Browse files Browse the repository at this point in the history
… of the futures in decoupled mode (#309) (#311)""

This reverts commit 5834064.
  • Loading branch information
kthui committed Dec 15, 2023
1 parent 088fb2c commit 7068edf
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/python_be.cc
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,7 @@ ModelInstanceState::DecoupledMessageQueueMonitor()
std::packaged_task<void()> task([this, response_send_message] {
ResponseSendDecoupled(response_send_message);
});
std::future<void> future =
boost::asio::post(*thread_pool_, std::move(task));
futures_.emplace_back(std::move(future));
boost::asio::post(*thread_pool_, std::move(task));
} else if (
message->Command() == PYTHONSTUB_InferExecRequest ||
message->Command() == PYTHONSTUB_InferStreamExecRequest) {
Expand All @@ -823,9 +821,7 @@ ModelInstanceState::DecoupledMessageQueueMonitor()
bls_execute,
(bls_execute->Command() == PYTHONSTUB_InferStreamExecRequest));
});
std::future<void> future =
boost::asio::post(*thread_pool_, std::move(task));
futures_.emplace_back(std::move(future));
boost::asio::post(*thread_pool_, std::move(task));
}
}
}
Expand Down Expand Up @@ -1879,12 +1875,14 @@ ModelInstanceState::~ModelInstanceState()
Stub()->UpdateHealth();
if (Stub()->IsHealthy()) {
if (model_state->IsDecoupled()) {
futures_.clear();
// Wait for all the pending tasks to finish.
thread_pool_->wait();
// Push a dummy message to signal the thread to terminate.
Stub()->ParentMessageQueue()->Push(DUMMY_MESSAGE);
decoupled_monitor_.join();
} else {
thread_pool_->wait();
}
thread_pool_->wait();
}
// Terminate stub first to allow any last messages to be received by the back
// end before deallocating the queue memory
Expand Down

0 comments on commit 7068edf

Please sign in to comment.