Proclets

class proclets.proclet.Proclet(*args, uid=None, name=None, channels=None, group=None, marking=None, slate=None, tally=None, trace=None, priority=None)

Proclets are callable objects which generate (yield) other objects. Their workflow is defined as a net of places and transitions. Each Proclet instance maintains a marking which determines which transitions are enabled at any particular time.

To use Proclets, first define a subclass:

class MyProc(Proclet):

    ...

Add behaviour by defining one or more transition methods. A reference to the method itself gets passed in as the parameter this when it is called:

def pro_one(self, this, **kwargs):
    ...

def pro_two(self, this, **kwargs):
    ...

Publish the workflow net as a directed graph:

@property
def net(self):
    return {
        self.pro_one: [self.pro_two],
        self.pro_two: []
    }

Use the create() method to obtain an instance:

p = MyProc.create()

When you call the Proclet, those transition methods will be enabled in the order defined by the net. When a transition method yields None, then operation flows on to the next.

Proclets will run forever if you let them. To halt operation, a transition may raise a proclets.types.Termination exception, which you can handle in the calling routine:

while True:
    try:
        for msg in p():
            print(msg)
    except Termination:
        break
population = <WeakValueDictionary>

This class attribute dictionary stores every created Proclet instance by its unique uid.

classmethod create(*args, fmt='{cls.__name__}_{0:03}', **kwargs)

This is the class factory method by which to create all Proclet objects.

New proclets are registered in the population dictionary so they can be retrieved by unique uid.

Keyword arguments may be any of the following (all are optional):

Parameters
  • uid (uuid.UUID) – A unique identifier for the object. Generated if not supplied.

  • name (str) – A human-readable name for the object. If not supplied, len(population) is passed to the format string fmt to generate one.

  • channels (dict) – A dictionary of named Channel objects.

  • group (set) – Contains the uid s of other Proclets to communicate with.

  • marking (set) – An initial numerical marking to enable Proclet transitions declared in the net.

  • slate (Counter) – The instance attribute slate stores the number of times a transition has blocked. You can initialise that via this parameter.

  • tally (Counter) – The instance attribute tally stores the number of times a transition has been enabled. You can initialise that via this parameter.

  • trace (deque) – This sequence stores the names of transitions fired, most recent first.

  • priority (int) – A numerical value for relative priority of execution. Smaller values have higher priority.

property net

This dictionary maps transition methods to a list of those which follow them in the net flow.

property enabled

The list of methods currently enabled by token positions.

property i_nodes

This dictionary maps transition methods to the numerical marking which enables them.

property o_nodes

This dictionary maps transition methods to the numerical marking they generate when fired.