title: python multiprocessing: How to modify a dictionary created in the main process from a subprocess?
body: <p>This question is related  to: <a href="https://stackoverflow.com/questions/6832554/multiprocessing-how-do-i-share-a-dict-among-multiple-processes">multiprocessing: How do I share a dict among multiple processes?</a></p>
  <p>I have multiple numpy arrays stored in a multiprocessing Dict. The multiprocessing dict is declared and populated with numpy arrays at predefined keys. each subprocess only writes and modifies data in a single key of the dict. The dictionary isnt updated by the subprocesses even thought the subprocesses seem to do something(shouldn't the dictionary be modified &quot;inplace&quot;, at the memory location of the dictionary declared in the main process?).</p>
  <p>I do not understand why it isn't working; is the data contained in the dict copied to each subprocess then modified in it and not returned to the main process? if that's the case, is there a way to modify the data without copying it somewhere else? In multiprocessing there may be a problem with unwanted data deletion when multiple processes try to write to the same adress, in my case, since each subprocess only writes to a specific key, will this unwanted data deletion be a problem?</p>
  <p>Sample code:</p>
  <pre><code>    
  import datetime
  import numpy as np
  import random
  from multiprocessing import Process,Manager
  
  class nbrgen(object):
      def __init__(self,ticker,TBA,delay):
          self.delay=delay
          self.value=100.00
          self.volume=50
          self.ticker=ticker
          self.TBA=TBA
  
      def generate_value(self):
          self.value=round (self.value + random.gauss(0,1)*self.delay + 0.01 ,2)
          self.volume=random.randint(1,100)
  
      def __next__(self):
          return self.next()
  
      def next(self):
          self.generate_value()
          t=datetime.datetime.now(tz=datetime.timezone.utc)
          return np.array([t,self.ticker,self.TBA,self.value,self.volume])
  
      def apenddict(D, tik,gnr):
        for i in range(8):
          print(tik)
          D[tik][:-1] = D[tik][1:]
          D[tik][-1:, :] = gnr.next()
  
  
      if __name__ ==&quot;__main__&quot;:
       manager=Manager()
       d=manager.dict()
       d[&quot;TOK&quot;] = np.zeros((10, 5), dtype=&quot;O&quot;)
       d[&quot;TIK&quot;] = np.zeros((10, 5), dtype=&quot;O&quot;)
   
       p1=Process(target=apenddict,args=(d,&quot;TIK&quot;,nbrgen(&quot;TIK&quot;,&quot;T&quot;,0.1)))
       p2=Process(target=apenddict,args=(d,&quot;TOK&quot;,nbrgen(&quot;TOK&quot;,&quot;T&quot;,0.1)))
  
       p1.start()
       p2.start()
       p1.join()
       p2.join()
  
       print(d)
  </code></pre>
  <p>prints: TIK and TOK randomly (as expected) and</p>
  <pre><code>{'TOK': array([[0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0]], dtype=object), 'TIK': array([[0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0]], dtype=object)}
  </code></pre>
  <p>is returned</p>