0

May I ask how can different process update the same dictionary in the concurrent.futures library? I understand that python built-in process does not talk with each other so what is the cannon way to get the process update the global dictionary? Here is a sample code

import concurrent.futures

quantity = {'apple': 0, 'pear': 0}
price = {'apple': 0, 'pear': 0}

args = [('apple', 1, 10), ('pear', 2,30)]

def update(args):
    quantity[args[0]] = args[1]
    price[args[0]] = args[2]


with concurrent.futures.ProcessPoolExecutor() as executor: 
    executor.map(update, args)

How can I get the executor to update the price and quantity dict? I tried to avoid ThreadPool since I do not know how to manage racing condition, which mess up a part of my project (I want to update a list and ThreadPool does not keep it in the order that I want).

Thank you very much

Ohhimark
  • 21
  • 3
  • Does this answer your question? [multiprocessing: How do I share a dict among multiple processes?](https://stackoverflow.com/questions/6832554/multiprocessing-how-do-i-share-a-dict-among-multiple-processes) – RafalS May 08 '20 at 11:54
  • Unfortunately no, I tried the manager.dict but it does not play along with the concurrent futures. – Ohhimark May 09 '20 at 06:21
  • What do you mean by `does not play along`? It works for me – RafalS May 10 '20 at 11:26
  • could you provide your code for this usecase? Mine refuses to update, im not sure how it when wrong. Thanks you very much – Ohhimark May 12 '20 at 03:56

0 Answers0