dragon.native.process

The Dragon native process object provides process management across one or multiple distributed systems. ProcessTemplate can hold a blueprint for a process that can be used to generate many similar processes.

Functions

current()

Get the PythonProcess object of the current process.

Classes

Popen

Process

This object describes a process managed by the Dragon runtime.

ProcessTemplate

This class provides a template for a Dragon process.

class ProcessTemplate

This class provides a template for a Dragon process.

__init__(target: str, args: Optional[tuple] = None, kwargs: Optional[dict] = None, cwd: str = '.', env: Optional[dict] = None, stdin: Optional[int] = None, stdout: Optional[int] = None, stderr: Optional[int] = None, policy: Optional[Policy] = None)

Generic Dragon process template object defining a process based on a binary executable or a Python callable.

If the target is a callable, define the Python process executing the callable. If the target is a string, assume it’s the filename of a binary to be started. If the target file is not found, the object tries to resolve the command via the PATH environment variable. If that fails, it assumes the file is in the current working directory.

This template cannot be started, but it can be used to create many similar processes like this:

```Python

t = ProcessTemplate(myfunc) p1 = Process.from_template(t, ident=”NewProcess1”) p2 = Process.from_template(t, ident=”NewProcess2”)

```

The template stores the absolute path of the target if the target is an executable. If the target is a Python function, the template stores the Python executable in its target attribute, the command line parameters in its args attribute and the Python data in its argdata attribute. To obtain the original attributes in Python use

```Python

target, args, kwargs = p.get_original_python_parameters()

```

Parameters
  • target (str or callable) – The binary or Python callable to execute.

  • args (tuple, optional) – arguments to pass to the binary or callable, defaults to None

  • kwargs (tuple, optional) – keyword arguments to pass to the Python callable, defaults to None

  • cwd (str, optional) – current working directory, defaults to “.”

  • env (dict, optional) – environment variables to pass to the process environment, defaults to None

  • stdin (int, optional) – Stdin file handling. Valid values are PIPE and None.

  • stdout (int, optional) – Stdout file handling. Valid values are PIPE, STDOUT and None.

  • stderr (int, optional) – Stderr file handling. Valid values are PIPE, STDOUT and None.

  • policy (dragon.infrastructure.policy.Policy) – determines the placement and resources of the process

get_original_python_parameters() tuple[callable, tuple, dict]

Return the original parameters of a Python process from the object.

Returns

function, args and kwargs of the templated process

Return type

tuple[callable, tuple, dict]

class Process

This object describes a process managed by the Dragon runtime.

__init__(target: str, args: Optional[tuple] = None, kwargs: Optional[dict] = None, cwd: str = '.', env: Optional[dict] = None, ident: Optional[str] = None, _pmi_enabled: bool = False, stdin: Optional[int] = None, stdout: Optional[int] = None, stderr: Optional[int] = None, policy: Optional[Policy] = None)

Generic Dragon process object executing a binary executable or a Python callable.

Processes are named and can be looked up by specifying the ident keyword: Process(None, ident="Apple")

If the target is a callable, start a new Python process executing the callable. The class uses cloudpickle to transfer the callable to the child process. See the cloudpickle documentation for possible limitations.

If the target is a string, assume it’s the filename of a binary to be started. If the target file is not found, the object tries to resolve the command via the PATH environment variable. If that fails, it assumes the file is in the current working directory.

The Process class should not be subclassed, because the Dragon runtime only holds on to attributes of the Process super class, breaking the name lookup.

Parameters
  • target (str or callable) – The binary or Python callable to execute.

  • args (tuple, optional) – arguments to pass to the binary or callable, defaults to None

  • kwargs (tuple, optional) – keyword arguments to pass to the Python callable, defaults to None

  • cwd (str, optional) – current working directory, defaults to “.”

  • env (dict, optional) – environment variables to pass to the process environment, defaults to None

  • ident (int or str) – unique id or name of this process

  • stdin (int, optional) – Stdin file handling. Valid values are PIPE and None.

  • stdout (int, optional) – Stdout file handling. Valid values are PIPE, STDOUT and None.

  • stderr (int, optional) – Stderr file handling. Valid values are PIPE, STDOUT and None.

  • policy (dragon.infrastructure.policy.Policy) – determines the placement and resources of the process

classmethod from_template(template: ProcessTemplate, ident: Optional[str] = None, _pmi_enabled: bool = False) object

A classmethod that creates a new process object from a template.

Parameters
  • template (ProcessTemplate) – the template to base the process on

  • ident (str, optional) – intended name of the process, defaults to None

Returns

The new process object

Return type

dragon.native.Process

start() None

Start the process represented by the underlying process object.

property is_alive: bool

Check if the process is still running

Returns

True if the process is running, False otherwise

Return type

bool

join(timeout: Optional[float] = None) int

Wait for the process to finish.

Parameters

timeout (float, optional) – timeout in seconds, defaults to None

Returns

exit code of the process, None if timeout occurs

Return type

int

Raises

ProcessError

terminate() None

Send SIGTERM signal to the process, terminating it.

Returns

None

Return type

NoneType

kill() None

Send SIGKILL signal to the process, killing it.

Returns

None

Return type

NoneType

property puid: int

Process puid. Globally unique

property node: int

Return the unique host id of the node the process is running on.

Returns

huid of host node.

Return type

int

property returncode: int

When the process has terminated, return exit code. None otherwise.

children() list[object]

Find all active children of the current process.

Returns

a list of p_uids of active children of the current process

Return type

list(int)

parent() object

Get the process object of the parent process. :returns: The puid or the parent of the current process :return type: int

current() Process

Get the PythonProcess object of the current process.

Returns

The current puid

Return type

int