I am looking for a way to pass information safely (!) between two processes of python scripts.
One process reads only, and the other writes only.
The data I need to pass is a dictionary.
The best solution I found so far is a local SQL server (since the data itself is kind of a table) and I assume SQLite will handle the transaction safely.
Is there a better way, maybe a module to lock a file from being read while it is written to and vice versa?
I am using linux ubuntu 11.10, but a cross platform solution will be welcome.
For one-way communication you could use e.g.
multiprocessing.Queueormultiprocessing.queues.SimpleQueue.Shared memory is also an option using
multiprocessing.Array. But you’d have to split up the dictionary in at least two arrays (keys and values). This will only work well if all the values are of the same basic type.The good point about both
multiprocessing.Queueandmultiprocessing.Arrayis that they are both protected by locks internally, so you don’t have to worry about that.