p4utils.utils.task_scheduler module

class p4utils.utils.task_scheduler.ProcessType[source]

Bases: enum.IntEnum

Enum class that defines task types.

CHAIN_SUBPROC = 2[source]
MULTIPROC = 0[source]
SUBPROC = 1[source]
class p4utils.utils.task_scheduler.Task(exe, start=0, duration=0, args=(), kwargs={})[source]

Bases: object

Abstraction of a Task executed by the TaskServer.

Parameters:
  • exe (str or types.FunctionType) – executable to run (either a shell string command or a python function)
  • start (int or float) – task absolute starting time (Unix time).
  • duration (int or float) – task duration time in seconds (if duration is lower than or equal to 0, then the task has no time limitation)
  • args (tuple or list) – positional arguments for the passed function
  • kwargs (dict) – key-word arguments for the passed function
exitcode[source]

Returns the exit code of the task.

Returns:exit code of the task.
Return type:int

Note

Returns None if the process has not yet terminated.

is_alive()[source]

Returns whether the process is alive.

Returns:True if the process is alive, False otherwise.
Return type:bool
join(timeout=None)[source]

Joins the subprocess.

pid[source]

Returns the PID of the task.

Returns:PID of the running task.
Return type:int

Note

Returns None if the task has not been started yet.

schedule(cond=None)[source]

Starts a new thread that orchestrate the execution of the task and stops it if duration expires.

Parameters:cond (threading.Condition) – condition to notify when self.thread is completed
setComm(q)[source]

Set communication queue for the Task. The task will communicate its state putting items in the queue.

Parameters:
  • id (int) – task id used to communicate
  • q (queue.Queue) – communication queue
start()[source]

Starts the executable in a separate process.

stop()[source]

Stops the task using SIGTERM and, if it fails, SIGKILL.

class p4utils.utils.task_scheduler.TaskClient(unix_socket_file)[source]

Bases: object

Task scheduler client which communicates with servers.

Parameters:unix_socket_file (str) – path to the file used by the Unix socket
send(tasks, retry=False)[source]

Send an object to the server and close connection.

Parameters:
  • tasks (list or tuple) – list or tuple of py:class:Task objects to execute
  • retry (bool) – whether to attempt a reconnection upon failure
class p4utils.utils.task_scheduler.TaskServer(unix_socket_file)[source]

Bases: object

Task scheduler server which runs on the Mininet nodes.

Parameters:unix_socket_file (string) – path to the file used by the Unix socket