nvflare.app_common.tie.process_mgr module

class CommandDescriptor(cmd: str, cwd=None, env=None, log_file_name: str = '', log_stdout: bool = True, stdout_msg_prefix: str | None = None)[source]

Bases: object

Constructor of CommandDescriptor. A CommandDescriptor describes the requirements of the new process to be started.

Parameters:
  • cmd – the command to be executed to start the new process

  • cwd – current work dir for the new process

  • env – system env for the new process

  • log_file_name – base name of the log file.

  • log_stdout – whether to output log messages to stdout.

  • stdout_msg_prefix – prefix to be prepended to log message when writing to stdout. Since multiple processes could be running within the same terminal window, the prefix can help differentiate log messages from these processes.

class ProcessManager(cmd_desc: CommandDescriptor)[source]

Bases: object

Constructor of ProcessManager. ProcessManager provides methods for managing the lifecycle of a subprocess (start, stop, poll), as well as the handling of log file to be used by the subprocess.

Parameters:

cmd_desc – the CommandDescriptor that describes the command of the new process to be started

NOTE: the methods of ProcessManager are not thread safe.

poll()[source]

Perform a poll request on the process.

Returns: None if the process is still running; an exit code (int) if process is not running.

start(fl_ctx: FLContext)[source]

Start the new process.

Parameters:

fl_ctx – FLContext object.

Returns: None

stop() int[source]

Stop the process. If the process is still running, kill the process. If a log file is open, close the log file.

Returns: the exit code of the process. If killed, returns -9.

start_process(cmd_desc: CommandDescriptor, fl_ctx: FLContext) ProcessManager[source]

Convenience function for starting a subprocess.

Parameters:
  • cmd_desc – the CommandDescriptor the describes the command to be executed

  • fl_ctx – FLContext object

Returns: a ProcessManager object.