Closed hperrey closed 3 months ago
Hi @hperrey,
Thank you for reporting this issue. It appears to be a regression, as I did not bump the major version according to SemVer, and this release should not have introduced any breaking changes.
I've identified that an automated test for "official support for multi-threaded applications" was missing, which is related to an existing issue: https://github.com/fgmacedo/python-statemachine/issues/403.
I appreciate the code snippet you provided. I will use it to reproduce and address the error.
Here are the next steps:
Thank you again!
Hi @hperrey , I've just released a patch version 2.3.1 that fixes this issue: https://pypi.org/project/python-statemachine/2.3.1/
Can you check if it works for you?
Thanks again for your detailed report, I was able to quickly reproduce the issue.
Best!
@fgmacedo this does indeed fix the issues I observed in all projects! Thank you so much for looking into this and even providing a fix on such a short timescale! Much obliged :)
Description
In a multi-threaded application, I am receiving and parsing commands on one thread which can trigger state machine changes. These are monitored on other threads by checking the state of the FSM. This design worked fine on versions before the recent introduction of
asyncio
but now result inRuntimeErrors
related to the event loop.What I Did
As a very simple reproducer, the following code demonstrates the issue I am facing:
Running the above code with
python-statemachine
2.3.0 results in the following output:while version 2.1.2 resulted in the expected
I would be very grateful for any advice you might have on how to fix this. I am not really familiar with
asyncio
and there might be an easy way around this issue that I just don't see.While the code above is of course far from perfect, the general design (FSM progressed from another thread) is something I am stuck with at the moment in more than one project -- the more I hope you might have an idea of how to make the code work even with more recent versions of
python-statemachine
!