MCPcopy Create free account
hub / github.com/NVIDIA/NeMo-Relay / start

Method start

crates/core/src/plugins/nemo_guardrails/python.rs:376–416  ·  view source on GitHub ↗
(config: &NeMoGuardrailsConfig)

Source from the content-addressed store, hash-verified

374
375impl 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);

Callers

nothing calls this directly

Calls 5

python_executableFunction · 0.85
worker_python_pathFunction · 0.85
spawnMethod · 0.80
spawn_readerMethod · 0.80
initializeMethod · 0.45

Tested by

no test coverage detected