Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions engine/cli/commands/server_start_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ bool ServerStartCmd::Exec(const std::string& host, int port,
commands.push_back(get_data_folder_path());
commands.push_back("--loglevel");
commands.push_back(log_level_);
auto pid = cortex::process::SpawnProcess(commands);
if (pid < 0) {
auto result = cortex::process::SpawnProcess(commands);
if (result.has_error()) {
// Fork failed
std::cerr << "Could not start server: " << std::endl;
std::cerr << "Could not start server: " << result.error() << std::endl;
return false;
} else {
// Parent process
Expand Down
15 changes: 10 additions & 5 deletions engine/extensions/python-engine/python_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,18 @@ void PythonEngine::LoadModel(

// Add the parsed arguments to the command
command.insert(command.end(), args.begin(), args.end());
pid = cortex::process::SpawnProcess(command);
process_map_[model] = pid;
if (pid == -1) {
auto result = cortex::process::SpawnProcess(command);

if (result.has_error()) {
CTL_ERR("Fail to spawn process. " << result.error());

std::unique_lock lock(models_mutex_);
if (models_.find(model) != models_.end()) {
models_.erase(model);
}

Json::Value error;
error["error"] = "Fail to spawn process with pid -1";
error["error"] = "Fail to spawn process";
Json::Value status;
status["is_done"] = true;
status["has_error"] = true;
Expand All @@ -304,6 +306,9 @@ void PythonEngine::LoadModel(
callback(std::move(status), std::move(error));
return;
}

pid = result.value().pid;
process_map_[model] = result.value();
} catch (const std::exception& e) {
std::unique_lock lock(models_mutex_);
if (models_.find(model) != models_.end()) {
Expand Down Expand Up @@ -356,7 +361,7 @@ void PythonEngine::UnloadModel(
} else {
Json::Value error;
error["error"] = "Fail to terminate process with id: " +
std::to_string(process_map_[model]);
std::to_string(process_map_[model].pid);
Json::Value status;
status["is_done"] = true;
status["has_error"] = true;
Expand Down
2 changes: 1 addition & 1 deletion engine/extensions/python-engine/python_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PythonEngine : public EngineI {
std::unordered_map<std::string, config::PythonModelConfig> models_;
extensions::TemplateRenderer renderer_;
std::unique_ptr<trantor::FileLogger> async_file_logger_;
std::unordered_map<std::string, pid_t> process_map_;
std::unordered_map<std::string, cortex::process::ProcessInfo> process_map_;
trantor::ConcurrentTaskQueue q_;

// Helper functions
Expand Down
6 changes: 3 additions & 3 deletions engine/services/hardware_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ bool HardwareService::Restart(const std::string& host, int port) {
commands.push_back(get_data_folder_path());
commands.push_back("--loglevel");
commands.push_back(luh::LogLevelStr(luh::global_log_level));
auto pid = cortex::process::SpawnProcess(commands);
if (pid < 0) {
auto result = cortex::process::SpawnProcess(commands);
if (result.has_error()) {
// Fork failed
std::cerr << "Could not start server: " << std::endl;
std::cerr << "Could not start server: " << result.error() << std::endl;
return false;
} else {
// Parent process
Expand Down
Loading
Loading