I'm writing software in python (3.7) that involves one main GUI thread, and multiple child processes that are each operating as state machines.
I'd like the child processes to publish their current state machine state name so the main GUI thread can check on what state the state machines are in.
I want to find a way to do this such that if the main process and the child process were trying to read/write to the state variable at the same time, the main process would immediately (with no locking/waiting) get a slightly out-of-date state, and the child process would immediately (with no locking/waiting) write the current state to the state variable.
Basically, I want to make sure the child process doesn't get any latency/jitter due to simultaneous access of the state variable, and I don't care if the GUI gets a slightly outdated value.
I looked into:
- using a
queue.Queue
with amaxsize
of1
, but the behavior ofqueue.Queue
is to block if the queue runs out of space - it would work for my purposes if it behaved like acollections.deque
and silently made the oldest value walk the plank if a new one came in with no available space. - using a
multiprocessing.Value
, but from the documentation, it sounds like you need to acquire a lock to access or write the value, and that's what I want to avoid - no locking/blocking for simultaneous read/writes. It says something vague about how if you don't use the lock, it won't be 'process-safe', but I don't really know what that means - what bad things would happen exactly without using a lock?
What's the best way to accomplish this? Thanks!