!6975 serving ctrl+c multi times exception fix

Merge pull request !6975 from 徐永飞/master
This commit is contained in:
mindspore-ci-bot 2020-09-28 19:48:28 +08:00 committed by Gitee
commit 58e9efb8aa
1 changed files with 8 additions and 1 deletions

View File

@ -26,6 +26,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <utility> #include <utility>
#include <atomic>
#include "include/infer_log.h" #include "include/infer_log.h"
#include "serving/ms_service.grpc.pb.h" #include "serving/ms_service.grpc.pb.h"
#include "core/util/option_parser.h" #include "core/util/option_parser.h"
@ -43,10 +44,16 @@ namespace serving {
namespace { namespace {
static const uint32_t uint32max = 0x7FFFFFFF; static const uint32_t uint32max = 0x7FFFFFFF;
std::promise<void> exit_requested; std::promise<void> exit_requested;
std::atomic_flag has_exited = ATOMIC_FLAG_INIT;
static const char kServerHttpIp[] = "0.0.0.0"; static const char kServerHttpIp[] = "0.0.0.0";
void ClearEnv() { Session::Instance().Clear(); } void ClearEnv() { Session::Instance().Clear(); }
void HandleSignal(int sig) { exit_requested.set_value(); } void HandleSignal(int sig) {
if (!has_exited.test_and_set()) {
exit_requested.set_value();
}
}
grpc::Status CreatGRPCStatus(const Status &status) { grpc::Status CreatGRPCStatus(const Status &status) {
switch (status.StatusCode()) { switch (status.StatusCode()) {