Arpit Bhayani arpitbhayani.me

Building finite state machines with Python Coroutines   ↦

An excellent, deep primer on both FSMs and using Coroutines in Python.

Even though this may not be the most efficient way to implement and build FSM but it is the most intuitive way indeed. The edges and state transitions, translate well into if and elif statements or the decision functions, while each state is being modeled as an independent coroutine and we still do things in a sequential manner. The entire execution is like a relay race where the baton of execution is being passed from one coroutine to another.


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00