Skip to content

pyscript doesn't run callback in transitions-based state machine #137

Closed
@renede

Description

@renede

Dear pyscript experts,
I am building a program that would benefit from using a state machine.
I tried to implement one, using the transitions package. The machine works, but callbacks which should be fired on a state transition don't. I tested the same code in 'regular' python 3.8, and there it worked.
The simplest code for reproducing:

from transitions import Machine, State
class C(object):
    def tst(self): log.info('Testing')
c = C()
states=[State('A', on_exit=['tst']),'B']
trans=[['go','A','B'],['back','B','A']]
m = Machine(c, states=states, transitions=trans, initial='A')
before = c.state
c.go()  # should call the callback and print 'Testing'
after = c.state
log.info(f'Before = {before}, After = {after}')
c.tst() # just check the callback

The result in jupyter:

Before = A, After = B
Testing

If I run almost the same code (just replacing log.info( ) by print( )) in jupyter with the python 3 kernel I get:

Testing
Before = A, After = B
Testing

In the pyscript case the function c.tst( ) is not called by the machine (the first 'Testing' missing), but that function does work as shown by the 'Testing' as the last line in the response.
I got the same result when running the test as a service in HA.
Is this a known limitation of pyscript, a bug, or am I doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions