-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pyscript doesn't run callback in transitions-based state machine #137
Comments
All functions in pyscript are (async) coroutines, not regular Python functions. So functions like In GitHub master there is an experimental feature that allows you to compile a function (so it's a regular Python function) using the Here's your code slightly modified to use Also, see issue #71 and this from transitions import Machine, State
class C(object):
tst_cnt = 0
@pyscript_compile
def tst(self):
self.tst_cnt += 1
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
log.info(f'tst_cnt = {c.tst_cnt}') This prints:
|
It seems that |
Dear Craig, Thanks for your very quick response! I wasn't aware of this |
Re-opening issue:
Result:
Now with the Hass kernel, the original call
Result: |
Your test exposed a couple of bugs related to calling pyscript functions from native Python async code. They should be fixed with the latest commit. Note that in your example, all four class methods are async in pyscript (the |
Sorry for my slow response. |
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:
The result in jupyter:
If I run almost the same code (just replacing
log.info( )
byprint( )
) in jupyter with the python 3 kernel I get: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?
The text was updated successfully, but these errors were encountered: