NumPy and memmap: [Errno 24] Too many open files

I work with large matrices, so I use the NumPy memmap. However, I am getting an error, because apparently the file descriptors used by memmap are not closing.

import numpy
import tempfile

counter = 0
while True:
    temp_fd, temporary_filename = tempfile.mkstemp(suffix='.memmap')
    map = numpy.memmap(temporary_filename, dtype=float, mode="w+", shape=1000)
    counter += 1
    print counter
    map.close()
    os.remove(temporary_filename)

From what I understand, the memmap file closes when the close () method is called. However, the above code cannot loop forever, because in the end it gives an error message " [Errno 24] Too many open files :

    1016
    1017
    1018
    1019
    Traceback (most recent call last):
      File "./memmap_loop.py", line 11, in <module>
      File "/usr/lib/python2.5/site-packages/numpy/core/memmap.py", line 226, in __new__
    EnvironmentError: [Errno 24] Too many open files
    Error in sys.excepthook:
    Traceback (most recent call last):
      File "/usr/lib/python2.5/site-packages/apport_python_hook.py", line 38, in apport_excepthook
    ImportError: No module named packaging_impl

    Original exception was:
    Traceback (most recent call last):
      File "./memmap_loop.py", line 11, in <module>
      File "/usr/lib/python2.5/site-packages/numpy/core/memmap.py", line 226, in __new__
    EnvironmentError: [Errno 24] Too many open files

Does anyone know what I'm missing?

+5
source share
1 answer

memmap , , , temp_fd. os.close(temp_fd)?


, .

numpy.memmap , , temp_fd.

fobj = os.fdopen(temp_fd, "w+")
numpy.memmap(fobj, ...
+4

All Articles