Pickle Fysom object?
Would this be possible? Or it is too crazy?
It currently errors the below with if you try to pickle the example in the README.
pickle.PicklingError: Can't pickle <function startup at 0x7f4b8c4492a8>: it's not found as fysom.startup
- I want to use the state machine over a series of web requests, and want to put it somewhere between requests.
Can't you hold it in-memory between requests (this would be possible with twisted for example, as it's single threaded)? Probably the most problematic part would be somehow marshalling the callbacks, if you use any. I'll have a closer look first thing tomorrow morning!
I am using Flask, and ideally I'd like to be able to run it in a threaded or in a load balanced environment.
Perhaps it would be easier to recreate the state machine each time and restore the state from persistent storage (pickle/redis etc).
I'm hoping to achieve this to vastly improve my code for handling inbound Twillio calls :-D
Is this still a problem for you? Serialization with callbacks doesn't look so good, due to the limitations when pickling functions or methods.
If you only use the current state of the state machine, it's easy to serialize it to a json-like string : it's basically the initial configuration, with initial set to fsm.current.
I suggest also supporting an standard format for (de)serialization, like .fsm file format. Specially, supporting creating the FSM object from an .fsm file would be a nice feature.
Hi @amiraliakbari , thanks for that link. Exporting/importing from .fsm files sounds great. This would leave dealing with callbacks to the developer which is also ok from my perspective since it's not required.