From 5834064cea5f1c3a1534658833e4eda26c6b7675 Mon Sep 17 00:00:00 2001 From: kthui <18255193+kthui@users.noreply.github.com> Date: Wed, 13 Dec 2023 18:37:09 -0800 Subject: [PATCH] [DO NOT MERGE] Revert "Restructure cleaning up of the futures in decoupled mode (#309) (#311)" This reverts commit d2bcb22b44ac8146b0d27ce17e58b437c10c9cca. --- src/python_be.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/python_be.cc b/src/python_be.cc index 6de5bcf3..6b8823a5 100644 --- a/src/python_be.cc +++ b/src/python_be.cc @@ -811,7 +811,9 @@ ModelInstanceState::DecoupledMessageQueueMonitor() std::packaged_task task([this, response_send_message] { ResponseSendDecoupled(response_send_message); }); - boost::asio::post(*thread_pool_, std::move(task)); + std::future future = + boost::asio::post(*thread_pool_, std::move(task)); + futures_.emplace_back(std::move(future)); } else if ( message->Command() == PYTHONSTUB_InferExecRequest || message->Command() == PYTHONSTUB_InferStreamExecRequest) { @@ -821,7 +823,9 @@ ModelInstanceState::DecoupledMessageQueueMonitor() bls_execute, (bls_execute->Command() == PYTHONSTUB_InferStreamExecRequest)); }); - boost::asio::post(*thread_pool_, std::move(task)); + std::future future = + boost::asio::post(*thread_pool_, std::move(task)); + futures_.emplace_back(std::move(future)); } } } @@ -1875,14 +1879,12 @@ ModelInstanceState::~ModelInstanceState() Stub()->UpdateHealth(); if (Stub()->IsHealthy()) { if (model_state->IsDecoupled()) { - // Wait for all the pending tasks to finish. - thread_pool_->wait(); + futures_.clear(); // 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