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.
-
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.
-
class
seqlib.nodes.
Sequence
(*, id=None, name=None)[source]¶ Basic sequencer node.
Use
create()
to build poperlySequence
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.
-
-
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 properlyParallel
nodes. Since it inherits fromSequence
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
-
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 properlyLoop
node. Since it inherits fromSequence
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
orActionInThread
. condition(node): condition nodeAction
orActionInThread
.- 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)