title: Why does Python hang when running mpirun within a subprocess?
body: <p>I have a very simple MPI script using mpi4py</p>
  
  <pre><code># mpitest.py
  from mpi4py import MPI
  import time
  
  comm = MPI.COMM_WORLD
  rank = comm.Get_rank()
  
  time.sleep(100)
  </code></pre>
  
  <p>If I run this normally with mpirun everything works fine</p>
  
  <pre><code>$ mpirun --np 4 python mpitest.py  # just fine
  </code></pre>
  
  <p>However if I run this from within Python using the subprocess module then things run, but my interpreter becomes very sluggish</p>
  
  <pre><code>&gt;&gt;&gt; import subprocess
  &gt;&gt;&gt; proc = subprocess.Popen(['mpirun', '--np', '2', 'python', 'mpitest.py'])
  </code></pre>
  
  <p>I've already tried keyword arguments like <code>shell=True</code>.</p>
  
  <h3>Environment</h3>
  
  <p>I've installed Python, mpi4py, and mpich using latest Miniconda for Linux</p>
  
  <pre><code>mrocklin@carbon:~/workspace/play$ conda list | grep mpi
  mpi4py                    2.0.0                    py36_2  
  mpich2                    1.4.1p1                       0  
  </code></pre>
  
  <p><a href="https://conda.io/miniconda.html" rel="noreferrer">https://conda.io/miniconda.html</a></p>
  
  <h3>Reproducible Steps</h3>
  
  <pre><code>mrocklin@carbon:~/workspace/play$ conda create -n test-mpi python=3.6 mpi4py
  Fetching package metadata .........
  Solving package specifications: .
  
  Package plan for installation in environment /home/mrocklin/Software/anaconda/envs/test-mpi:
  
  The following NEW packages will be INSTALLED:
  
      mpi4py:     2.0.0-py36_2 
      mpich2:     1.4.1p1-0    
      openssl:    1.0.2l-0     
      pip:        9.0.1-py36_1 
      python:     3.6.2-0      
      readline:   6.2-2        
      setuptools: 27.2.0-py36_0
      sqlite:     3.13.0-0     
      tk:         8.5.18-0     
      wheel:      0.29.0-py36_0
      xz:         5.2.3-0      
      zlib:       1.2.11-0     
  
  xz-5.2.3-0.tar 100% |################################| Time: 0:00:00   3.79 MB/s
  zlib-1.2.11-0. 100% |################################| Time: 0:00:00   5.68 MB/s
  #
  # To activate this environment, use:
  # &gt; source activate test-mpi
  #
  # To deactivate an active environment, use:
  # &gt; source deactivate
  #
  
  mrocklin@carbon:~/workspace/play$ source activate test-mpi
  (test-mpi) mrocklin@carbon:~/workspace/play$ python
  Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32) 
  [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; import subprocess
  &gt;&gt;&gt; proc = subprocess.Popen(['mpirun', '--np', '2', 'python', 'mpitest.py'])
  </code></pre>