提交 68c0f1bc 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!5638 Make the kernel build server not quit.

Merge pull request !5638 from 张清华/master
...@@ -59,7 +59,8 @@ class KernelBuildClient { ...@@ -59,7 +59,8 @@ class KernelBuildClient {
// Exception's thrown if open failed // Exception's thrown if open failed
if (dp_->Open({GetEnv(), GetScript()}, true) != -1) { if (dp_->Open({GetEnv(), GetScript()}, true) != -1) {
dp_->SetTimeOutSeconds(kTimeOutSeconds); dp_->SetTimeOutSeconds(kTimeOutSeconds);
dp_->SetTimeOutCallback([this]() { SendRequest(kFinish); }); dp_->SetTimeOutCallback(std::make_shared<std::function<void()>>([this]() { SendRequest(kFinish); }));
dp_->SetFinalizeCallback(std::make_shared<std::function<void()>>([this]() { Close(); }));
init_ = true; init_ = true;
} }
} }
......
...@@ -168,7 +168,7 @@ void DuplexPipe::SignalHandler::CancelAlarm() { alarm(0); } ...@@ -168,7 +168,7 @@ void DuplexPipe::SignalHandler::CancelAlarm() { alarm(0); }
void DuplexPipe::SignalHandler::SigAlarmHandler(int sig) { void DuplexPipe::SignalHandler::SigAlarmHandler(int sig) {
DP_INFO << "Signal: " << sig << ", child_pid_: " << child_pid_; DP_INFO << "Signal: " << sig << ", child_pid_: " << child_pid_;
if (!dp_.expired()) { if (!dp_.expired()) {
dp_.lock()->TimeOut(); dp_.lock()->NotifyTimeOut();
} }
} }
...@@ -184,9 +184,9 @@ void DuplexPipe::SignalHandler::SigChildHandler(int sig) { ...@@ -184,9 +184,9 @@ void DuplexPipe::SignalHandler::SigChildHandler(int sig) {
int status; int status;
auto pid = waitpid(child_pid_, &status, WNOHANG | WUNTRACED); auto pid = waitpid(child_pid_, &status, WNOHANG | WUNTRACED);
if (WIFEXITED(status)) { if (WIFEXITED(status)) {
DP_INFO << "Child exited, status: " << WEXITSTATUS(status) << ", pid: " << pid; DP_INFO << "Child exited, status: " << WEXITSTATUS(status) << ", pid: " << pid << ", dp expired: " << dp_.expired();
if (!dp_.expired()) { if (pid > 0 && !dp_.expired()) {
dp_.lock()->Close(); dp_.lock()->NotifyFinalize();
} }
} else if (WIFSTOPPED(status)) { } else if (WIFSTOPPED(status)) {
DP_INFO << "Child stopped, sig: " << WSTOPSIG(status) << ", pid: " << pid; DP_INFO << "Child stopped, sig: " << WSTOPSIG(status) << ", pid: " << pid;
......
...@@ -45,10 +45,8 @@ class DuplexPipe : public std::enable_shared_from_this<mindspore::DuplexPipe> { ...@@ -45,10 +45,8 @@ class DuplexPipe : public std::enable_shared_from_this<mindspore::DuplexPipe> {
int Open(std::initializer_list<std::string> arg_list, bool append_fds = false); int Open(std::initializer_list<std::string> arg_list, bool append_fds = false);
void Close(); void Close();
void SetTimeOutSeconds(unsigned int secs) { time_out_secs_ = secs; } void SetTimeOutSeconds(unsigned int secs) { time_out_secs_ = secs; }
void SetTimeOutCallback(const std::function<void()> &cb) { void SetTimeOutCallback(const std::shared_ptr<std::function<void()>> cb) { time_out_callback_ = cb; }
has_time_out_callback_ = true; void SetFinalizeCallback(const std::shared_ptr<std::function<void()>> cb) { finalize_callback_ = cb; }
time_out_callback_ = cb;
}
// Write the 'buf' to remote stdin // Write the 'buf' to remote stdin
void Write(const std::string &buf, bool flush = true); void Write(const std::string &buf, bool flush = true);
...@@ -64,14 +62,20 @@ class DuplexPipe : public std::enable_shared_from_this<mindspore::DuplexPipe> { ...@@ -64,14 +62,20 @@ class DuplexPipe : public std::enable_shared_from_this<mindspore::DuplexPipe> {
private: private:
void SetTimeOut() { signal_handler_->SetAlarm(time_out_secs_); } void SetTimeOut() { signal_handler_->SetAlarm(time_out_secs_); }
void CancelTimeOut() { signal_handler_->CancelAlarm(); } void CancelTimeOut() { signal_handler_->CancelAlarm(); }
void TimeOut() { void NotifyTimeOut() {
if (has_time_out_callback_) { if (time_out_callback_ != nullptr) {
time_out_callback_(); (*time_out_callback_)();
} }
Close(); Close();
DP_EXCEPTION << "Time out when read from pipe"; DP_EXCEPTION << "Time out when read from pipe";
} }
void NotifyFinalize() {
if (finalize_callback_ != nullptr) {
(*finalize_callback_)();
}
}
// Subprocess id in parent process, // Subprocess id in parent process,
// otherwise zero in child process. // otherwise zero in child process.
pid_t pid_; pid_t pid_;
...@@ -115,8 +119,8 @@ class DuplexPipe : public std::enable_shared_from_this<mindspore::DuplexPipe> { ...@@ -115,8 +119,8 @@ class DuplexPipe : public std::enable_shared_from_this<mindspore::DuplexPipe> {
}; };
unsigned int time_out_secs_ = kTimeOutSeconds; unsigned int time_out_secs_ = kTimeOutSeconds;
bool has_time_out_callback_ = false; std::shared_ptr<std::function<void()>> time_out_callback_;
std::function<void()> time_out_callback_; std::shared_ptr<std::function<void()>> finalize_callback_;
std::shared_ptr<SignalHandler> signal_handler_; std::shared_ptr<SignalHandler> signal_handler_;
}; };
} // namespace mindspore } // namespace mindspore
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册