title: Python: How to return values in a multiprocessing situation?
body: <p>Let's say I have a collection of <code>Process</code>-es, <code>a[0]</code> through <code>a[m]</code>.</p>
  
  <p>These processes will then send a job, via a queue, to another collection of <code>Process</code>-es, <code>b[0]</code> through <code>b[n]</code>, where <code>m &gt; n</code></p>
  
  <p>Or, to diagram:</p>
  
  <pre><code>a[0], a[1], ..., a[m] ---Queue---&gt; b[0], b[1], ..., b[n]
  </code></pre>
  
  <p>Now, how do I return the result of the <code>b</code> processes to the relevant <code>a</code> process?</p>
  
  <p>My first guess was using <code>multiprocessing.Pipe()</code></p>
  
  <p>So, I've tried doing the following:</p>
  
  <pre><code>## On the 'a' side
  pipe = multiprocessing.Pipe()
  job['pipe'] = pipe
  queue.put(job)
  rslt = pipe[0].recv()
  
  ## On the 'b' side
  job = queue.get()
  ... process the job ...
  pipe = job['pipe']
  pipe.send(result)
  </code></pre>
  
  <p>and it doesn't work with the error: <code>Required argument 'handle' (pos 1) not found</code></p>
  
  <p>Reading many docs, I came up with:</p>
  
  <pre><code>## On the 'a' side
  pipe = multiprocessing.Pipe()
  job['pipe'] = multiprocessing.reduction.reduce_connection(pipe[1])
  queue.put(job)
  rslt = pipe[0].recv()
  
  ## On the 'b' side
  job = queue.get()
  ... process the job ...
  pipe = multiprocessing.reduction.rebuild_connection(job['pipe'], True, True)
  pipe.send(result)
  </code></pre>
  
  <p>Now I get a different error: <code>ValueError: need more than 2 values to unpack</code>.</p>
  
  <p>I've tried searching and searching and still can't find how to properly use the <code>reduce_</code> and <code>rebuild_</code> methods.</p>
  
  <p>Please help so I can return the value from <code>b</code> to <code>a</code>.</p>