title: Multiprocessing in Python: impossible to get back my results (get()) (happens rarely)
body: <p>I use Multiprocessing in Python in order to do several requests to a database (and other stuff):</p>
  
  <pre><code>po = multiprocessing.Pool()
  for element in setOfElements:
      results.append(po.apply_async(myDBRequestModule, (element, other stuff...)))                    
  po.close()
  po.join()
  for r in results:
      newSet.add(r.get())
  </code></pre>
  
  <p>myDBRequestModule returns an object I defined, made of a list and two numbers. I redefined the hash function, in order to define what I mean by equality in my sets of these objects:</p>
  
  <pre><code>class myObject:
      def __init__(self, aList, aNumber, anotherNumber):
          self.list = aList
          self.number1 = aNumber
          self.number2 = anotherNumber
      def __hash__(self):
          # turn elements of list into a string, in order to hash the string
          hash_text = ""
          for element in self.list:
              hash_text += str(element.x.id) # I use the ID of the element of my list...
          return hash(hash_text)
      def __eq__(self, other):
          self_hash_text = ""
          other_hash_text = ""
          for element in self.list:
              self_hash_text += str(element.x.id)
          for element in other.listDest:
              other_hash_text += str(element.x.id)
          return self_hash_text == other_hash_text 
  </code></pre>
  
  <p>And in most cases it works as it should. Twice, for no known reason and in exactly the same context, I had a bug:</p>
  
  <pre><code>newSet.add(r.get())
  File "/usr/lib/python2.6/multiprocessing/pool.py", line 422, in get
      raise self._value
  TypeError: 'str' object does not support item assignment
  </code></pre>
  
  <p>It comes from the get method (last line):</p>
  
  <pre><code>def get(self, timeout=None):
      self.wait(timeout)
      if not self._ready:
          raise TimeoutError
      if self._success:
          return self._value
      else:
          raise self._value
  </code></pre>
  
  <p>Since I had this mistake only once and it disappeared, I decided to give up earlier, but it created a second problem recently, and I really don't know how to fight this bug.
  In particular, it's difficult for me to tell why it happens almost never, and usually works perfectly fine.</p>