title: Passing a dict-like Object through multiprocessing.Queue Makes it Unable to be Modified by Attribute
body: <p>Actually I am not sure whether the title describes the problem appropriately. Let me show the code.</p>
  
  <pre><code>import os
  from multiprocessing import JoinableQueue
  
  # A dict-like class, but is able to be accessed by attributes.
  # example: d = AttrDict({'a': 1, 'b': 2})
  # d.a is equivalent to d['a']
  class AttrDict(dict):
      def __init__(self, *args, **kwargs):
          super(AttrDict, self).__init__(*args, **kwargs)
          self.__dict__ = self
  
  
  queue = JoinableQueue()
  pid = os.fork()
  
  if pid == 0:
      d = AttrDict({'a': 1, 'b': 2})
      queue.put(d)
      queue.join()
      os._exit(0)
  else:
      d = queue.get()
      queue.task_done()
      #d = AttrDict(d.items())  #(1)
      d.a = 3                   #(2)
      #d['a'] = 3               #(3)
      print d
  </code></pre>
  
  <p>The above code prints <code>{'a': 1, 'b': 2}</code>, which means (2) is not taking any effect.</p>
  
  <p>If I change (2) to (3), or enable (1), then the output is <code>{'a': 3, 'b': 2}</code>, which is expected.</p>
  
  <p>Seems something happened to <code>d</code> when it is passed through queue. </p>
  
  <p>Tested with Python 2.7.</p>
  
  <hr>
  
  <p>Solution:</p>
  
  <p>As pointed out by @kindall and @Blckknght, the reason is that <code>d</code> is picked as a dict and when it is unpickled by <code>queue.get()</code>, the <code>self.__dict__ = self</code> magic is not set. The difference can be seem by <code>print d.__dict__</code> and <code>print d</code>.</p>
  
  <p>To set the magic back, I added the method <code>__setstate__</code> to <code>AttrDict</code>:</p>
  
  <pre><code>class AttrDict(dict):
      def __init__(self, *args, **kwargs):
          super(AttrDict, self).__init__(*args, **kwargs)
          self.__dict__ = self
  
      def __setstate__(self, state):
          self.__dict__ = state
  </code></pre>
  
  <p>The code now works as expected.</p>