Skip to content

State transition during on_exception callback causes RecursionError #617

Answered by aleneum
e0lithic asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @e0lithic,

it's not the on_exception callback that causes recursion errors here but the repetitive attempt to exit failure.

The logic here is:

next_state -> on_exit_failing -> handle_error -> to_failure -> on_exit_failing -> handle_error ...

If your on_exit callback may fail you need another approach.

You could a) 'hard set' your model to another state to avoid on_exit_failing:

    def handle_error(self):
        self.machine.set_state('failure')
        self.to_failure()

You could b) make the failing operation 'state-sensitive':

    def handle_error(self):
        self.error_state = True
        self.to_failure()

    def on_exit_failing(self):
        if not self.error_state:
   …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by e0lithic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants
Converted from issue

This discussion was converted from issue #616 on April 02, 2023 16:30.