seqlib.nodes package

Sequencer nodes

Implements all node types and utility functions.

Module contents

class seqlib.nodes.Action(f=None, *, id=None, name=None)[source]

Bases: seqlib.nodes.interface._BaseNode

Action ctor.

Action nodes executes coroutines in a Sequencer script.

Parameters

f (coroutine) – The coroutine the node will execute

Keyword Arguments
  • id (str) – Unique id. If not provided an unique identifier is assigned.

  • name (str) – Node name. If not provided a name is assigned.

Raises

TypeException – is f is not a coroutine.

class seqlib.nodes.ActionInThread(f=None, *, id=None, name=None)[source]

Bases: seqlib.nodes.action.Action

ActionInThread ctor.

ActionInThread nodes executes python callables (functions or methods) in a Sequencer script.

Parameters

f (callable) – The callable the node will execute

Keyword Arguments
  • id (str) – Unique id. If not provided an unique identifier is assigned.

  • name (str) – Node name. If not provided a name is assigned.

Raises

TypeException – is f is not a python method or function.

class seqlib.nodes.Sequence(*, id=None, name=None)[source]

Basic sequencer node.

Use create() to build poperly Sequence objects.

state

node state

Context Variables

Name

Desc

current_tpl

The parent of the current node

root

Top level DAG’s root

Examples

>>> s = Sequence.create(a,b, name="my sequence")
# execute Sequence
>>> await s.start()
# Get running Sequence from Inside function a():
>>> def a():
...     current_tpl = Sequence.current_tpl
...     # now current_tpl is the node s
...     assert current_tpl == s
abort()[source]

Aborts the sequence.

Goes trough the full graph and aborts the tasks associated to nodes (if any).

property context

Get context dictionary, preferably from root node.

static create(*args, **kw)[source]

Sequence node constructor.

Parameters

*args – Variable length list of nodes or coroutines that compose the sequence.

Keyword Arguments
  • id – Node id

  • name – node name

async resume()[source]

Resume node execution

start(make_sequence=True, resume=False)[source]

This is the entry point for Sequence execution.

Returns

Returns the SeqTask object that executes the sequence

Raises

Exception – Any exception received is re-raised and the sequence is aborted.

class seqlib.nodes.Parallel(*, id=None, name=None, seq_args=NOTHING)[source]

Bases: seqlib.nodes.sequence.Sequence

Parallel node definition.

Use the create() method to build properly Parallel nodes. Since it inherits from Sequence it has access to the same context variables.

Example

One can access the running Sequence using Sequence.current_tpl context variable.

>>> s = Parallel.create(a,b, name="my sequence")
# execute Sequence
>>> await s.start()
# Get running Sequence from Inside function a():
>>> def a():
...     current_tpl = Sequence.current_tpl
...     # now current_tpl is the node s
...     assert current_tpl == s
static create(*args, **kw)[source]

Creates a Parallel node

Parameters

*args

Variable length list of nodes or coroutines that compose the sequence.

Keyword Args:

id: Node id name: node name

class seqlib.nodes.Loop(*, id=None, name=None, block_args=NOTHING, condition=None, init=None)[source]

Bases: seqlib.nodes.sequence.Sequence

Loop node definition.

Use the create() method to build properly Loop node. Since it inherits from Sequence it has access to the same context variables.

Context Variables

Name

Desc

current_tpl

The parent of the current node (from Sequence)

root

Top level DAG’s root (from Sequence)

index

The Loop’s current index (starts at 0)

Keyword Arguments
  • id (Optional str) – Node id.

  • name (Optional str) – Node name.

  • init (Optional) – Initialization node.

  • condition (callale) – A Python method that returns a boolean value.

  • block (list) – The loop’s body.

static create(*args, **kw)[source]

Creates a Loop node

Parameters

*args

Variable length list of nodes or coroutines that comprises the Loop`s body.

Keyword Args:

id: Node id name: node name init (node) : initialization node Action or ActionInThread. condition(node): condition node Action or ActionInThread.

Returns:

A new Loop object

Example:

Creating a loop.

def eval_condition():
    return False

class Tpl:
    def initialize(self, context):
        # performs some initialization
        pass
    async def a():
        pass
    async def b():
        pass

    @staticmethod
    def create()
        t = MyClass()
        l = Loop.create(t.a, t.b, condition=eval_condition, init=t.initialize)