use pyo3::prelude::*;
mod builtins;
mod conversions;
mod error;
mod manager;
mod result;
use manager::PyPluginManager;
use result::PyPipelineResult;
const ENV_WORKER_THREADS: &str = "CPEX_PY_WORKER_THREADS";
fn worker_threads_from_env() -> Option<usize> {
let raw = std::env::var(ENV_WORKER_THREADS).ok()?;
match raw.parse::<usize>() {
Ok(n) if n > 0 => {
tracing::info!(
"cpex-python: runtime using {} worker threads (from {})",
n,
ENV_WORKER_THREADS,
);
Some(n)
},
_ => {
tracing::warn!(
"cpex-python: {}={:?} is not a positive integer; using num_cpus default",
ENV_WORKER_THREADS,
raw,
);
None
},
}
}
#[pymodule]
fn _lib(m: &Bound<'_, PyModule>) -> PyResult<()> {
let mut builder = tokio::runtime::Builder::new_multi_thread();
builder.enable_all();
if let Some(n) = worker_threads_from_env() {
builder.worker_threads(n);
}
pyo3_async_runtimes::tokio::init(builder);
m.add_class::<PyPluginManager>()?;
m.add_class::<PyPipelineResult>()?;
Ok(())
}