parent
2c9bad43fb
commit
342e4d7b41
@ -1,14 +1,15 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "engine"
|
name = "swarms-runtime" # The name of your project
|
||||||
version = "0.1.0"
|
version = "0.1.0" # The current version, adhering to semantic versioning
|
||||||
edition = "2018"
|
edition = "2021" # Specifies which edition of Rust you're using, e.g., 2018 or 2021
|
||||||
|
authors = ["Your Name <your.email@example.com>"] # Optional: specify the package authors
|
||||||
[lib]
|
license = "MIT" # Optional: the license for your project
|
||||||
name = "engine"
|
description = "A brief description of my project" # Optional: a short description of your project
|
||||||
path = "runtime/concurrent_exec.rs"
|
|
||||||
crate-type = ["cdylib"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pyo3 = { version = "0.15", features = ["extension-module"] }
|
cpython = "0.5"
|
||||||
rayon = "1.5.1"
|
rayon = "1.5"
|
||||||
log = "0.4.14"
|
|
||||||
|
[dependencies.pyo3]
|
||||||
|
version = "0.20.3"
|
||||||
|
features = ["extension-module", "auto-initialize"]
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
use pyo3::prelude::*;
|
||||||
|
use pyo3::types::PyList;
|
||||||
|
use rayon::prelude::*;
|
||||||
|
use std::fs;
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
// Define the new execute function
|
||||||
|
fn execute(script_path: &str, threads: usize) -> PyResult<()> {
|
||||||
|
(0..threads).into_par_iter().for_each(|_| {
|
||||||
|
Python::with_gil(|py| {
|
||||||
|
let sys = py.import("sys").unwrap();
|
||||||
|
let path: &PyList = match sys.getattr("path") {
|
||||||
|
Ok(path) => match path.downcast() {
|
||||||
|
Ok(path) => path,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Failed to downcast path: {:?}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Failed to get path attribute: {:?}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(e) = path.append("lib/python3.11/site-packages") {
|
||||||
|
eprintln!("Failed to append path: {:?}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
let script = fs::read_to_string(script_path).unwrap();
|
||||||
|
py.run(&script, None, None).unwrap();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> PyResult<()> {
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
let threads = 20;
|
||||||
|
|
||||||
|
if args.len() < 2 {
|
||||||
|
eprintln!("Usage: {} <path_to_python_script>", args[0]);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
let script_path = &args[1];
|
||||||
|
|
||||||
|
let start = Instant::now();
|
||||||
|
|
||||||
|
// Call the execute function
|
||||||
|
execute(script_path, threads)?;
|
||||||
|
|
||||||
|
let duration = start.elapsed();
|
||||||
|
match fs::write("/tmp/elapsed.time", format!("booting time: {:?}", duration)) {
|
||||||
|
Ok(_) => println!("Successfully wrote elapsed time to /tmp/elapsed.time"),
|
||||||
|
Err(e) => eprintln!("Failed to write elapsed time: {:?}", e),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in new issue