dwhall / farc

Framework for state machines with run-to-completion concurrency using asyncio. Python 3.4 or later
MIT License
28 stars 6 forks source link

Posting/publishing events only creates a shallow copy of the data #2

Closed dwhall closed 5 years ago

dwhall commented 5 years ago

An event is a tuple of (signal, value). farc does not protect the application author from making the following mistake: passing a Python object in the value field that is shallow-copied to the event recipient. So if the author passes a Python list, the sender and receiver of the event now have references to the same list. This is Bad.

The framework should automatically fix this. I'm not aware of all of the ways (or the best way) to fix this. The two methods that come to mind are: (1) to scan the value and use Python calls to ensure a deep copy is made. and (2) to use a data serializer (Pickle et al, MsgPack) and put the serialized representation of the Python object in the event's value.

I'm partial to method 2 because I think it might allow greater flexibility for future uses of farc, such as issuing events across a network. But I want to make sure performance isn't harmed for the simple cases.

I'm open to suggestions on this.