As far a 1, I'd recommend just use functools.partial or make an object with all the extra stuff u want and have that object provide a __call__ method.

As far as 2, you might have to subclass the FSM baseclass and add those into the internal data-structure (same for 3 I think); ie this one @

Of course feel free to do it differently and submit a patch that folks (myself and others) can review.


Kwan, Louie wrote:

Friendly state machines for python.

A few questions about automaton.

1.I would like to know can we addition parameters on on_enter or on_exit
callbacks. Right now, it seems it only allows state and triggered_event.

a.I have many FSM running for different objects and it is much easier if
I can pass on the some sort of ID back to the callbacks.

2.Can we or how can we store extra attribute like last state change

3.Can we store additional identify info for the FSM object? Would like
to add an */UUID/*



def print_on_enter(new_state, triggered_event):

print("Entered '%s' due to '%s'" % (new_state, triggered_event))

def print_on_exit(old_state, triggered_event):

print("Exiting '%s' due to '%s'" % (old_state, triggered_event))

# This will contain all the states and transitions that our machine will

# allow, the format is relatively simple and designed to be easy to use.

state_space = [


'name': 'stopped',

'next_states': {

# On event 'play' transition to the 'playing' state.

'play': 'playing',

'open_close': 'opened',

'stop': 'stopped',


'on_enter': print_on_enter,

'on_exit': print_on_exit,


OpenStack Development Mailing List (not for usage questions)

OpenStack Development Mailing List (not for usage questions)

Reply via email to