title: Python multiprocessing code using pipes hangs at first .recv() method when Pipes are generated automatically
body: <p>I'm writing some bogus practice code so I can implement the ideas once I have a better idea of what I'm doing. The code is designed for multiprocessing in order to reduce the runtime by splitting the stack of three arrays into several pieces horizontally that are then executed in parallel via <code>map_async</code>. However, the code seems to hang at the first <code>.recv()</code> method of a pipe, even though the <code>Pipe()</code> object is fully defined, and I'm not sure why it's doing it. If I manually define each <code>Pipe()</code> object then the code works just fine, but as soon as I iterate the process the code hangs at <code>sec1 = pipes[0][0].recv()</code>. How can I fix this?</p>
  
  <pre><code>from multiprocessing import Process, Pipe
  import multiprocessing as mp
  import numpy as np
  import math
  
  num_sections = 4
  
  pipes_send = [None]*num_sections
  pipes_recv = [None]*num_sections
  pipes = zip(pipes_recv,pipes_send)
  
  for i in range(num_sections):
      pipes[i] = list(pipes[i])
  
  for i in range(num_sections):
      pipes[i][0],pipes[i][1] = Pipe()
  
  def f(sec_num):
      for plane in range(3):
          hist_sec[sec_num][plane] += rand_sec[sec_num][plane]
      if sec_num == 0:
          pipes[0][1].send(hist_sec[sec_num])
          pipes[0][1].close()
      if sec_num == 1:
          pipes[1][1].send(hist_sec[sec_num])
          pipes[1][1].close()
      if sec_num == 2:
          pipes[2][1].send(hist_sec[sec_num])
          pipes[2][1].close()
      if sec_num == 3:
          pipes[3][1].send(hist_sec[sec_num])
          pipes[3][1].close()
  
  
  hist = np.zeros((3,512,512))
  hist_sec = []
  randmat = np.random.rand(3,512,512)
  rand_sec = []
  for plane in range(3):
      hist_div = np.array_split(hist[plane], num_sections)
      hist_sec.append(hist_div)
      randmatsplit = np.array_split(randmat[plane], num_sections)
      rand_sec.append(randmatsplit)
  
  hist_sec = np.rollaxis(np.asarray(hist_sec),1,0)
  rand_sec = np.rollaxis(np.asarray(rand_sec),1,0)
  
  
  if __name__ == '__main__':
  
      pool = mp.Pool(num_sections)
      args = np.arange(num_sections)
      pool.map_async(f, args, chunksize=1)
      sec1 = pipes[0][0].recv()
      sec2 = pipes[1][0].recv()
      sec3 = pipes[2][0].recv()
      sec4 = pipes[3][0].recv()
      for plane in range(3):
          hist_plane = np.concatenate((sec1[plane],sec2[plane],sec3[plane],sec4[plane]),axis=0)
          hist_full.append(hist_plane)
      pool.close()
      pool.join()
  </code></pre>