<p dir="auto">On Windows 32 bit, current Python 2.7.8 from Python.org Python, numpy 1.9.1 superpack installer, scipy 0.14.0 superpack installer.</p>
<p dir="auto">I run the following <code class="notranslate">test.py</code> Python script from the shell:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import scipy.sparse._sparsetools
import sys
sys.exit(2)"><pre class="notranslate"><code class="notranslate">import scipy.sparse._sparsetools
import sys
sys.exit(2)
</code></pre></div>
<p dir="auto">with <code class="notranslate">c:\Python27\python.exe test.py</code>.  I check the return code with <code class="notranslate">echo %errorlevel%</code> and get 0, when I am expecting 2.  I get 2 if I comment out the scipy import.  This is after emptying out <code class="notranslate">scipy.__init__.py</code> and <code class="notranslate">scipy.sparse.__init__.py</code>.  The import of <code class="notranslate">_sparsetools</code> appears to be removing control of the process exit code.  This is a real problem for example with buildbot tests, because test runs that are failing nevertheless have an exit code of 0 - see for example the end of <a href="http://nipy.bic.berkeley.edu/builders/dipy-py2.7-win32/builds/106/steps/shell_6/logs/stdio" rel="nofollow">http://nipy.bic.berkeley.edu/builders/dipy-py2.7-win32/builds/106/steps/shell_6/logs/stdio</a></p>
<p dir="auto">Any ideas what might be going on?</p>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/1314" rel="nofollow">http://projects.scipy.org/scipy/ticket/1314</a> on 2010-10-18 by trac user markMiscavage, assigned to <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/wnbell/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/wnbell">@wnbell</a>.</em></p>
<p dir="auto">I have this bug in a larger program but I've narrowed it down to a script consisting of just :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import sys
import scipy.sparse.sparsetools
sys.exit(&quot;EXIT&quot;)"><pre class="notranslate"><code class="notranslate">import sys
import scipy.sparse.sparsetools
sys.exit("EXIT")
</code></pre></div>
<p dir="auto">This will always exit with code 0. It seems it is the .pyd files in the sparsetools folder that are the source of this problem. I have the same problem in both 0.7.1 and 0.8.0 builds of scipy. I am using python 2.6 on a Windows 7 - 64 bit system.</p>