fysom icon indicating copy to clipboard operation
fysom copied to clipboard

Pickle Fysom object?

Open firegrass opened this issue 12 years ago • 5 comments

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.

firegrass avatar Apr 28 '14 21:04 firegrass

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!

mriehl avatar Apr 28 '14 22:04 mriehl

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

firegrass avatar Apr 29 '14 07:04 firegrass

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.

mriehl avatar May 27 '14 13:05 mriehl

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.

amiraliakbari avatar Jun 18 '14 08:06 amiraliakbari

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.

mriehl avatar Jun 18 '14 09:06 mriehl