nvflare.app_common.tie.py_applet module

class PyApplet(in_process: bool)[source]

Bases: Applet, ABC

Constructor of PyApplet, which runs the applet’s Python code in a separate thread or subprocess.

Parameters:

in_process – whether to run the applet code as separate thread within the same process or as a separate subprocess.

abstract get_runner(app_ctx: dict) PyRunner[source]

Subclass must implement this method to return a PyRunner. The returned PyRunner must be pickleable since it could be run in a separate subprocess!

Parameters:

app_ctx – the app context for the runner

Returns: a PyRunner object

is_stopped() -> (<class 'bool'>, <class 'int'>)[source]

Called to check whether the applet is already stopped.

Returns: whether the applet is stopped, and the exit code if stopped.

start(app_ctx: dict)[source]

Start the execution of the applet.

Parameters:

app_ctx – the app context

Returns:

stop(timeout=0.0) int[source]

Stop the applet

Parameters:

timeout – amount of time to wait for the applet to stop by itself. If the applet does not stop on its own within this time, we’ll forcefully stop it by kill.

Returns: None

class PyRunner[source]

Bases: ABC

A PyApplet must return a light-weight PyRunner object to run the Python code of the external app. Since the runner could be running in a separate subprocess, the runner object must be pickleable!

abstract is_stopped() -> (<class 'bool'>, <class 'int'>)[source]

Check whether the app code is stopped

Returns: a tuple of: whether the app is stopped, and exit code if stopped

abstract start(app_ctx: dict)[source]

Start the external app’s Python code

Parameters:

app_ctx – the app’s execution context

Returns:

abstract stop(timeout: float)[source]

Stop the external app’s python code

Parameters:

timeout – how long to wait for the app to stop before killing it

Returns: None