0

I am writing application which is running multiple processes. Each process operates on the same dictionary (locked by Lock()). How to make sure we can edit that dictionary inside process ?

Example:

 from multiprocessing import Process
 p = Process(target=self.search_simple_process, args=(self,content,patterns,))
 p.start()
 p.join()
 self.out(patterns)

 def search_simple_process(self, content, patterns):
    for pattern in patterns.keys():
        try:                           
            if pattern in content:
                patterns[pattern] += 1 #to add Lock() for this
        except:
            self.out("Exception")  

Right now the results displayed are always original patterns dictionary (not modified).

Thanks, Michal

user2913139
  • 557
  • 2
  • 5
  • 13
  • Possible dup of http://stackoverflow.com/questions/17224277/share-dict-between-processes – dhke Jun 16 '15 at 07:31
  • You have to use a [multiprocessing.Manager.dict](https://docs.python.org/2/library/multiprocessing.html#multiprocessing.managers.SyncManager). See an example [here](https://docs.python.org/2/library/multiprocessing.html#sharing-state-between-processes). – Vincent Jun 16 '15 at 07:59
  • possible duplicate of [Python multiprocessing: How do I share a dict among multiple processes?](http://stackoverflow.com/questions/6832554/python-multiprocessing-how-do-i-share-a-dict-among-multiple-processes) – CoMartel Jun 16 '15 at 08:13

0 Answers0