Skip to content
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

How to run transition #373

Closed
galhyt opened this issue Mar 13, 2023 · 8 comments
Closed

How to run transition #373

galhyt opened this issue Mar 13, 2023 · 8 comments

Comments

@galhyt
Copy link

galhyt commented Mar 13, 2023

  • Python State Machine version: 2.0.0
  • Python version: 3.7.16
  • Operating System:

Description

How do I run transition? in version 0.9.0 I would run it like this:
source = State(...)
target = State(...)
transition = source.to(target)
sm.(...)

def on_(**kwargs):
if can't move to target:
raise

How can I do it in version 2?

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
@fgmacedo
Copy link
Owner

Hi @galhyt , it should work the same.

The main difference is that I've made explicit the difference between Event and Transition. An event is the name of the trigger bound to one or more transitions, and transition is any arc that connect two states.

Taking your example:

transition = source.to(target)
  • transition is the event name.
  • source.to(target) is the transition.

If your system is more event-oriented, you can use the sm.send(<event_name>):

sm.send("transition")

Or if you want to call the event in an imperative-style programming, you can still call the event as a method:

sm.transition()

Please see https://python-statemachine.readthedocs.io/en/latest/transitions.html for a more complete explanation.

Best regards!

@galhyt
Copy link
Author

galhyt commented Mar 19, 2023

Hi @fgmacedo,

But does it calling on_transition (on_event) function as it used to in 0.9.0?

@fgmacedo
Copy link
Owner

fgmacedo commented Mar 19, 2023

Yes. Are you getting an error? Or an action not being called?

@galhyt
Copy link
Author

galhyt commented Mar 19, 2023

The function on_transition is not being called

@fgmacedo
Copy link
Owner

fgmacedo commented Mar 19, 2023

The function on_transition is not being called

Can you please copy-paste or write a complete example that reproduces the error that I can run locally?

We have automated tests to test this callback, so maybe is something easy like a typo that a fresh look on the code can spot.

@galhyt
Copy link
Author

galhyt commented Mar 19, 2023

Ok I will,
Tnx

@galhyt
Copy link
Author

galhyt commented Mar 20, 2023

Ok, I managed with this problem.
I had a decorator to each event's method so I just removed it and moved the logic else where.

@fgmacedo
Copy link
Owner

Nice! Closing the issue. Feel free to reach out any time.

Best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants