[Numpy-discussion] .transpose() of memmap array fails to close()

Glen W. Mabey Glen.Mabey@swri....
Fri Aug 10 11:20:16 CDT 2007


Hello,

I posted this a while back and didn't get any replies.  I'm running in
to this issue again from a different aspect, and today I've been trying
to figure out which method of ndarray needs to be overloaded for memmap
so that the the ._mmap attribute gets handled appropriately.

But, I have not been able to figure out what methods of ndarray are
getting used in code such as this:

>>> import numpy
>>> amemmap = numpy.memmap( '/tmp/afile', dtype=numpy.float32,
>>> shape=(4,5), mode='w+' )
>>> b = amemmap[2:3]
>>> b
>>> Exception exceptions.AttributeError: "'memmap' object has no attribute '_mmap'" in <bound method memmap.__del__ of memmap([ 0.,  0.,  0.,  0.,  0.], dtype=float32)> ignored memmap([[ 0.,  0.,  0.,  0.,  0.]], dtype=float32)


Furthermore, can anyone enlighten me as to why an AttributeError
exception would be ignored?

Am I using numpy.memmap instances appropriately?

Thank you,
Glen Mabey




On Thu, Jun 07, 2007 at 04:46:20PM -0500, Glen W. Mabey wrote:
> Hello,
> 
> When assigning a variable that is the transpose() of a memmap array, the
> ._mmap member doesn't get copied, I guess:
> 
> In [1]:import numpy
> 
> In [2]:amemmap = numpy.memmap( '/tmp/afile', dtype=numpy.float32, shape=(4,5), mode='w+' )
> 
> In [3]:bmemmap = amemmap.transpose()
> 
> In [4]:bmemmap.close()
> ---------------------------------------------------------------------------
> <type 'exceptions.AttributeError'>        Traceback (most recent call last)
> 
> /home/gmabey/src/R9619_dev_acqlibweb/Projects/R9619_NChannelDetection/NED/<ipython console> in <module>()
> 
> /usr/local/stow/numpy-20070605_svn-py2.5/lib/python2.5/site-packages/numpy/core/memmap.py
> in close(self)
>      86 
>      87     def close(self):
> ---> 88         self._mmap.close()
>      89 
>      90     def __del__(self):
> 
> <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'close'
> > /usr/local/stow/numpy-20070605_svn-py2.5/lib/python2.5/site-packages/numpy/core/memmap.py(88)close()
>      87     def close(self):
> ---> 88         self._mmap.close()
>      89 
> 
> 
> 
> 
> This is an issue when the data is accessed in an order that is different
> from how it is stored on disk, as:
> 
> bmemmap = numpy.memmap( '/tmp/afile', dtype=numpy.float32, shape=(4,5), mode='w+' ).transpose()
> 
> So the object that was originally produced not accessible.  I imagine
> there is some better way to indicate order of dimensions, but
> regardless, doing
> 
> In [4]:bmemmap._mmap = amemmap._mmap
> 
> is a hack workaround.
> 
> Best regards,
> Glen Mabey
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion


More information about the Numpy-discussion mailing list