<p dir="auto">This appears to be a defect that is specific to Intel's Math Kernel Library and the resolution will likely require changes therein. I'm submitting here as I believe the NumPy team has some relationships/connections with the Intel team and there have been some efforts to make MKL work well with NumPy (and SciPy). I am using Python 3.6.4, built from source on OSX 10.13.4 and Linux 16.04 (WSL). NumPy is built from source using gcc 7.1.0 on Mac and gcc 7.2 on Linux.</p>
<p dir="auto">When executed with python3 this script will hang the terminal on OSX and Linux. No tests have been performed on Win64. If the size of the vector, x, is reduced by a factor of 10 to 1000, no hang is observed and the script executes correctly. The hang is specific to the call to linalg.norm. It is likely caused by multi-threaded execution of the norm() method using MKL's infrastructure, leaving the system in a state that interferes with Python execution of subprocess.run(). I also get a hang when using Python's Multiprocessing module process creation in place of subprocess.run().</p>
<p dir="auto">This is important for a few reasons 1) Jupyter QtConsole &amp; Notebook and IPython use subprocess.run() to execute certain os commands (such as ls). Hence we get a hang when working in all these applications. 2) If you want to spawn or fork to subprocesses to execute cpu intensive tasks you'll get a hang if you've previously called np.linalg.norm() with a sufficiently large vector (and perhaps many other NumPy and SciPy calls).</p>
<h3 dir="auto">Reproducing code example:</h3>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
import subprocess

x = np.arange(10000) # 1000 shows no hang.
xnorm = np.linalg.norm(x)

subprocess.run('ls')"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">subprocess</span>

<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">10000</span>) <span class="pl-c"># 1000 shows no hang.</span>
<span class="pl-s1">xnorm</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">linalg</span>.<span class="pl-en">norm</span>(<span class="pl-s1">x</span>)

<span class="pl-s1">subprocess</span>.<span class="pl-en">run</span>(<span class="pl-s">'ls'</span>)</pre></div>
<h3 dir="auto">Error message:</h3>
<p dir="auto">No error message, just a hang.</p>
<h3 dir="auto">Numpy/Python version information:</h3>
<p dir="auto">NumPy 1.14.3<br>
Python 3.6.4<br>
MKL: l_mkl_2018.3.222, m_mkl_2018.3.185</p>
<p dir="auto">Hello!</p>
<p dir="auto">Linux Mint: 18.3 (Sylvia)<br>
Python: 3.6.3<br>
NumPy: 1.13.3<br>
Cython 0.27.3</p>
<p dir="auto">I am trying to build numpy and scipy wheels from source using the intel mkl compilers. Numpy compiles just fine, however when I run the test suite, the suite hangs on <code class="notranslate">test_path_type_input</code> within <code class="notranslate">test_einsum.TestEinSumPath</code> (or maybe the test after it? not sure because the last test name visible is this one; see screen cap)</p>
<p dir="auto">Running the test suite for scipy results in the suite hanging on <code class="notranslate">test_lapack</code> within <code class="notranslate">test_build.TestF77Mismatch</code></p>
<p dir="auto">In both cases (numpy and scipy) the tests run and pass fine when run individually, so I'm not sure what else might be the cause.</p>
<p dir="auto">Any help is greatly appreciated. See screen shot for images of the test suites when they're stuck is included.<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/7530947/33036734-90a4cba6-cdec-11e7-8014-025c4f0904f1.png"><img src="https://user-images.githubusercontent.com/7530947/33036734-90a4cba6-cdec-11e7-8014-025c4f0904f1.png" alt="numpy" style="max-width: 100%;"></a><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/7530947/33036738-92df0c24-cdec-11e7-93f7-0b0417779e7c.png"><img src="https://user-images.githubusercontent.com/7530947/33036738-92df0c24-cdec-11e7-93f7-0b0417779e7c.png" alt="scipy" style="max-width: 100%;"></a></p>