<p dir="auto">Consider the following code:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy
from numpy.linalg import inv
from multiprocessing import Process

def hang():
    a = numpy.identity(3)
    b = inv(a)


p = Process(target=hang)
p.start()
p.join()"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span>
<span class="pl-k">from</span> <span class="pl-s1">numpy</span>.<span class="pl-s1">linalg</span> <span class="pl-k">import</span> <span class="pl-s1">inv</span>
<span class="pl-k">from</span> <span class="pl-s1">multiprocessing</span> <span class="pl-k">import</span> <span class="pl-v">Process</span>

<span class="pl-k">def</span> <span class="pl-en">hang</span>():
    <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">numpy</span>.<span class="pl-en">identity</span>(<span class="pl-c1">3</span>)
    <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-en">inv</span>(<span class="pl-s1">a</span>)


<span class="pl-s1">p</span> <span class="pl-c1">=</span> <span class="pl-v">Process</span>(<span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-s1">hang</span>)
<span class="pl-s1">p</span>.<span class="pl-en">start</span>()
<span class="pl-s1">p</span>.<span class="pl-en">join</span>()</pre></div>
<p dir="auto">If numpy uses OpenBLAS, it hangs forever consuming 100% CPU with OPENBLAS_NUM_THREADS&gt;1. If export OPENBLAS_NUM_THREADS=1, it works OK.<br>
I am testing this code on 32-core machine, if this matters.<br>
It may be related to issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="7718708" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/654" data-hovercard-type="issue" data-hovercard-url="/numpy/numpy/issues/654/hovercard" href="https://github.com/numpy/numpy/issues/654">#654</a></p>
<p dir="auto">numpy version 1.8.1<br>
python version 3.4.1<br>
openblas version 0.2.8<br>
ubuntu 14.04</p>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/2201" rel="nofollow">http://projects.scipy.org/numpy/ticket/2201</a> on 2012-08-14 by trac user agchang, assigned to <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/pv/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/pv">@pv</a>.</em></p>
<p dir="auto">There seems to be an issue with numpy.linalg being called in unison with python's multiprocessing module. When invoking a numpy.linalg method from within a subprocess, e.g., through a worker pool and map() function, the program hangs and ignores all interrupt signals.</p>
<p dir="auto">The code provided below will demonstrate the case:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy as np
import multiprocessing as mp

def foo(x):
    print np.linalg.inv([[2,3],[2,2]]) #this causes the crash
    #print np.dot([[1,2],[3,4]],[[1,2],[3,4]]) # this works fine

def test():
    print &quot;running...&quot;
    print np.__version__
    print mp.__version__
    vals = [1,2,3,4]
    #pool = mp.Pool(1) #This has an issue
    #pool = mp.Pool(mp.cpu_count()) #this has an issue
    pool.map(foo, vals)

if __name__ == &quot;__main__&quot;:
    test() 
    #foo(1) #this works fine"><pre class="notranslate"><code class="notranslate">import numpy as np
import multiprocessing as mp

def foo(x):
    print np.linalg.inv([[2,3],[2,2]]) #this causes the crash
    #print np.dot([[1,2],[3,4]],[[1,2],[3,4]]) # this works fine

def test():
    print "running..."
    print np.__version__
    print mp.__version__
    vals = [1,2,3,4]
    #pool = mp.Pool(1) #This has an issue
    #pool = mp.Pool(mp.cpu_count()) #this has an issue
    pool.map(foo, vals)

if __name__ == "__main__":
    test() 
    #foo(1) #this works fine
</code></pre></div>
<p dir="auto">By hang I mean the program becomes unresponsive and does not respond to interrupts(Ctrl-C).</p>
<p dir="auto">I took a look using pdb and it seems that it hangs after the call<br>
<strong>waiter</strong>.acquire() in threading.py(the python system module) so I suspect some sort of deadlock?</p>
<p dir="auto">multiprocessing.<strong>version</strong> is 0.70a1<br>
numpy.<strong>version</strong> is 1.6.1</p>
<p dir="auto">Some potentially related packages?</p>
<p dir="auto">ii  libblas3gf     1.2.20110419-2 Basic Linear Algebra Reference implementatio<br>
ii  liblapack3gf   3.3.1-1        library of linear algebra routines 3 - share<br>
ii  python         2.7.3-0ubuntu2 interactive high-level object-oriented langu<br>
ii  python-numpy   1:1.6.1-6ubunt Numerical Python adds a fast array facility</p>
<p dir="auto">My kernel version is(uname -a):</p>
<p dir="auto">Linux agc 3.2.0-29-generic <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="647645" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/46" data-hovercard-type="pull_request" data-hovercard-url="/numpy/numpy/pull/46/hovercard" href="https://github.com/numpy/numpy/pull/46">#46</a>-Ubuntu SMP Fri Jul 27 17:03:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux</p>
<p dir="auto">Let me know for any additional information.</p>
<p dir="auto">Thanks.</p>