Skip to content

Conversation

@rodrigobnogueira
Copy link

Description

When an async state machine is pickled and unpickled (e.g., via multiprocessing.Process), calling activate_initial_state() fails with InvalidStateValue: There's no current state set.

Root Cause

In __setstate__, the engine is recreated but engine.start() is never called, so the initial __initial__ event is never enqueued. When the user calls await sm.activate_initial_state(), there's nothing in the queue to process.

Fix

Added self._engine.start() to __setstate__ so the initial transition is properly enqueued after deserialization.

Testing

Added regression test test_pickle_async_statemachine in tests/test_copy.py.

Fixes #544

When an async state machine is pickled and unpickled (e.g., via
multiprocessing.Process), calling activate_initial_state() fails.

The root cause is that __setstate__ recreates the engine but doesn't
call engine.start(), so the initial __initial__ event is never enqueued.

This commit adds self._engine.start() to __setstate__ so the initial
transition is properly enqueued after deserialization.

Fixes fgmacedo#544

Signed-off-by: rodrigo.nogueira <rodrigo.nogueira@prf.gov.br>
@sonarqubecloud
Copy link

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

Successfully merging this pull request may close these issues.

Bug using async state machine with multiprocessing

1 participant