[NumPy-Tickets] [NumPy] #1654: possible race condition with savez
NumPy Trac
numpy-tickets@scipy....
Thu Oct 28 22:09:41 CDT 2010
#1654: possible race condition with savez
------------------------+---------------------------------------------------
Reporter: unclepedro | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 2.0.0
Component: Other | Version: 1.5.0
Keywords: savez |
------------------------+---------------------------------------------------
Hi,
np.savez is not multi-process safe, because it always uses gettempdir() +
key + ".npy". So, if you're running the same script over different data
sets, you will roach your own data when one process removes the
/tmp/arr_0.npy of another process.
As luck would have it, I'm in that exact situation, so I have an example
error:
Traceback (most recent call last):
File "/home/pedro/prospectus/prelim/bbvs/bin/skldthresh", line 99, in
<module>
main()
File "/home/pedro/prospectus/prelim/bbvs/bin/skldthresh", line 90, in
main
np.savez("%smask-t%0.2f" % (outfile,threshold), result)
File "/usr/lib/python2.5/site-packages/numpy/lib/io.py", line 230, in
savez
zip.write(filename, arcname=fname)
File "/usr/lib/python2.5/zipfile.py", line 541, in write
st = os.stat(filename)
OSError: [Errno 2] No such file or directory: '/tmp/arr_0.npy'
Fortunately, replacing tempfile.gettempdir() with tempfile.mkdtemp() AND
remembering to clean up at the end with os.rmdir(direc) is all it takes to
fix it as far as I can tell.
Attached is a patch.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1654>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list