using numpy.memmap to map a device file

帅比萌擦擦* 提交于 2019-12-05 18:32:00

If your code works fine with the python mmap module, you can use it directly instead of numpy.memmap:

>>> fd = os.open("a", os.O_RDWR)
>>> buffer = mmap.mmap(fd, 0)
>>> surface = np.ndarray((320,240), np.uint16, buffer)

This has the other advantage that you have more control over the memory mapping used.

Now, python's mmap has its own peculiarities. As the source shows, it calls msync on delallocation. Maybe this is where your program hangs? (You might be able to reproduce your issue with buffer.flush(), which also calls msync). Your solution of calling close() first probably works because it circumvents msync!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!