Reputation: 3260
In python multiprocessing, I have a dictionary of type Manager.dict()
, the value of this dictionary is a list of strings, in order to to get the dictionary properly shared between processes, do I need to use the normal list or Manager.list()
as the value type?
Upvotes: 0
Views: 801
Reputation: 28252
Manager.dict()
will manage accesses into the arrays, no Manager.list()
required. The dictionary returned by Manager.dict()
will be a proxy to the real dictionary that lives on the manager.
The manager will let you read the lists, however it will not automatically persist any changes you make to them. For that, you'll have to set the values in your client code when you're done working with them. See the note on the bottom of the reference entry for details.
This will trigger a transmission of the entire list, which can be expensive. What's worse, it doesn't provide you with any safety guarantees regarding concurrent writing, so in two processes write the same list at the same time, only the second write will overwrite the first one.
I unfortunately can't suggest any alternative because I don't know enough about the tradeoffs you're able to make. Feel free to post another question, describing those, though!
Upvotes: 1