(config: &NeMoGuardrailsConfig)
| 374 | |
| 375 | impl LocalGuardrailsWorker { |
| 376 | fn start(config: &NeMoGuardrailsConfig) -> PluginResult<Arc<Self>> { |
| 377 | let python = python_executable(config); |
| 378 | let mut command = Command::new(&python); |
| 379 | command |
| 380 | .arg("-u") |
| 381 | .arg("-c") |
| 382 | .arg(WORKER_SCRIPT) |
| 383 | .stdin(Stdio::piped()) |
| 384 | .stdout(Stdio::piped()) |
| 385 | .stderr(Stdio::inherit()); |
| 386 | if let Some(python_path) = worker_python_path(config) { |
| 387 | command.env("PYTHONPATH", python_path); |
| 388 | } |
| 389 | |
| 390 | let mut child = command.spawn().map_err(|err| { |
| 391 | PluginError::RegistrationFailed(format!( |
| 392 | "failed to start NeMo Guardrails local Python worker with {python:?}: {err}" |
| 393 | )) |
| 394 | })?; |
| 395 | let stdin = child.stdin.take().ok_or_else(|| { |
| 396 | PluginError::RegistrationFailed( |
| 397 | "failed to open stdin for NeMo Guardrails local Python worker".to_string(), |
| 398 | ) |
| 399 | })?; |
| 400 | let stdout = child.stdout.take().ok_or_else(|| { |
| 401 | PluginError::RegistrationFailed( |
| 402 | "failed to open stdout for NeMo Guardrails local Python worker".to_string(), |
| 403 | ) |
| 404 | })?; |
| 405 | |
| 406 | let worker = Arc::new(Self { |
| 407 | writer: Mutex::new(Some(WorkerCommandWriter::spawn(stdin))), |
| 408 | child: Mutex::new(child), |
| 409 | waiters: Arc::new(Mutex::new(HashMap::new())), |
| 410 | stream_events: Arc::new(Mutex::new(HashMap::new())), |
| 411 | next_id: AtomicU64::new(1), |
| 412 | }); |
| 413 | worker.spawn_reader(stdout); |
| 414 | worker.initialize(config)?; |
| 415 | Ok(worker) |
| 416 | } |
| 417 | |
| 418 | fn spawn_reader(&self, stdout: ChildStdout) { |
| 419 | let waiters = Arc::clone(&self.waiters); |
nothing calls this directly
no test coverage detected