pytransitions / transitions

A lightweight, object-oriented finite state machine implementation in Python with many extensions
MIT License
5.49k stars 525 forks source link

maximum recursion depth exceeded while calling a Python object #612

Closed alpxe closed 1 year ago

alpxe commented 1 year ago

from transitions import State, Machine

class Matter:

def helloAAA(self):
    print(f"hello {self.state}")
    self.toB()

def helloBBB(self):
    print(f"hello {self.state}")
    self.toC()

def helloCCC(self):
    print(f"hello {self.state}")
    self.toA()

def __init__(self):
    states = [
        State(name='S', on_enter='say_hello'),
        State(name='A', on_enter='helloAAA'),
        State(name='B', on_enter='helloBBB'),
        State(name='C', on_enter='helloCCC'),
    ]
    self.machine = Machine(model=self, states=states, initial="S")

    self.machine.add_transition(trigger='starting', source='S', dest='A')
    self.machine.add_transition(trigger='toB', source='A', dest='B')
    self.machine.add_transition(trigger='toC', source='B', dest='C')
    self.machine.add_transition(trigger='toA', source='C', dest='A')

lump = Matter()

lump.starting()

Unable to loop??? The requirement are step by step , then exit but it is wrong!!!!!

alpxe commented 1 year ago

lump.starting()

while True: if lump.state == "A": lump.toB() elif lump.state == "B": lump.toC() elif lump.state == "C": lump.toA()

and >>> This is right