dummynet.ProcessMonitor

class dummynet.ProcessMonitor(log)

The basic idea behind the monitor is to coordinate a process execution.

Typically scenario:

  1. Run measurement software between two hosts

  2. Start a server side waiting for clients to connect

  3. Start a client and stop test once client exits

We should also ensure that the server applications started in 2 keeps running throughout the test and that it is closed when the client application exits.

class Process(cmd, cwd, env, sudo, is_async, is_daemon, timeout, poller)

A process object to track the state of a process

Parameters:
  • cmd (str | list[str])

  • cwd (str | None)

  • sudo (bool)

  • is_async (bool)

  • is_daemon (bool)

  • timeout (int | float | None)

  • poller (ProcessMonitor.Poller)

__init__(cmd, cwd, env, sudo, is_async, is_daemon, timeout, poller)

Construct a new process object.

Parameters:
  • cmd (str | list[str])

  • cwd (str | None)

  • sudo (bool)

  • is_async (bool)

  • is_daemon (bool)

  • timeout (int | float | None)

  • poller (Poller)

is_running()

Poll the process and update the return code

stop(timeout=1.0)

Stop a process

Parameters:

timeout (float)

__init__(log)

Create a new test monitor

keep_running(timeout=0.1)

Run the process monitor.

Parameters:

timeout – A timeout in milliseconds. If this timeout expires we return.

Returns:

True on timeout and processes are still running. If no processes are running anymore return False.

The following simple loop can be used to keep the monitor running while waiting for processes to exit:

while test_monitor.keep_running():

pass

stop(validate_state=True, timeout=1.0)

Stop all processes

Parameters:
  • timeout (int | float) – Time in seconds to wait for SIGTERM to stop each active process until SIGKILL is sent.

  • validate_state (bool) – If we should validate state before stopping all processes and daemons. Do not disable this unless you know what you are doing!

stop_process_async(target, timeout=1.0)

Stop and remove a process managed by ProcessMonitor.

Parameters:
  • target (RunInfo) – The RunInfo object returned by run_process_async you want to stop.

  • timeout (float) – Time in seconds to wait for SIGTERM to stop the active process until SIGKILL is sent.