nvflare.utils.process_utils module
- class ProcessAdapter(process: Popen | None = None, pid: int | None = None)[source]
Bases:
objectAdapter to manage a process, whether created via subprocess.Popen or os.posix_spawn.
- Parameters:
process – The subprocess.Popen object (if created via subprocess)
pid – The process ID (if created via posix_spawn, or fallback for process.pid)
- poll() int | None[source]
Check if the process has terminated.
- Returns:
None if process is still running, otherwise the exit code.
- spawn_process(cmd_args: List[str], env: dict) ProcessAdapter[source]
Launch a process using posix_spawn if available, falling back to subprocess.Popen.
This method attempts to use os.posix_spawn with setsid=True to avoid fork() related issues (such as gRPC deadlocks). If posix_spawn is unavailable or fails, it falls back to subprocess.Popen with preexec_fn=os.setsid.
- Parameters:
cmd_args – The command arguments as a list of strings.
env – The environment variables dictionary.
- Returns:
An adapter wrapping the launched process.
- Return type: