Browse Source

Fix spawning runtime through python when it is installed with pip (#1011)

This PR fixes #900 by checking the current exe of the daemon. 

If the daemon is running on python => spawn the runtime on python.
If the daemon is running on a dora binary => use current dora binary.

Alternative to #940
tags/v0.3.12-rc0
Haixuan Xavier Tao GitHub 7 months ago
parent
commit
d9a1b508c8
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 42 additions and 9 deletions
  1. +42
    -9
      binaries/daemon/src/spawn.rs

+ 42
- 9
binaries/daemon/src/spawn.rs View File

@@ -27,7 +27,7 @@ use dora_node_api::{
arrow_utils::{copy_array_into_sample, required_data_size},
Metadata,
};
use eyre::{ContextCompat, WrapErr};
use eyre::{bail, ContextCompat, WrapErr};
use std::{
path::{Path, PathBuf},
process::Stdio,
@@ -269,7 +269,7 @@ pub async fn spawn_node(
"-n",
conda_env,
"python",
"-c",
"-uc",
format!("import dora; dora.start_runtime() # {}", node.id).as_str(),
]);
command
@@ -295,20 +295,53 @@ pub async fn spawn_node(
};
// Force python to always flush stdout/stderr buffer
cmd.args([
"-c",
"-uc",
format!("import dora; dora.start_runtime() # {}", node.id).as_str(),
]);
cmd
}
} else if python_operators.is_empty() && other_operators {
let mut cmd = tokio::process::Command::new(
std::env::current_exe().wrap_err("failed to get current executable path")?,
);
cmd.arg("runtime");
cmd
let current_exe =
std::env::current_exe().wrap_err("failed to get current executable path")?;
let mut file_name = current_exe.clone();
file_name.set_extension("");
let file_name = file_name
.file_name()
.and_then(|s| s.to_str())
.context("failed to get file name from current executable")?;

// Check if the current executable is a python binary meaning that dora is installed within the python environment
if file_name.ends_with("python") || file_name.ends_with("python3") {
// Use the current executable to spawn runtime
let python = get_python_path()
.wrap_err("Could not find python path when spawning custom node")?;
let mut cmd = tokio::process::Command::new(python);

tracing::info!(
"spawning: python -uc import dora; dora.start_runtime() # {}",
node.id
);

cmd.args([
"-uc",
format!("import dora; dora.start_runtime() # {}", node.id).as_str(),
]);
cmd
} else {
let mut cmd = tokio::process::Command::new(
std::env::current_exe()
.wrap_err("failed to get current executable path")?,
);
cmd.arg("runtime");
cmd
}
} else {
eyre::bail!("Runtime can not mix Python Operator with other type of operator.");
bail!(
"Cannot spawn runtime with both Python and non-Python operators. \
Please use a single operator or ensure that all operators are Python-based."
);
};

command.current_dir(working_dir);

let runtime_config = RuntimeConfig {


Loading…
Cancel
Save