Logan Gunthorpe <log...@deltatee.com> added the comment:

Paul's solution works in 3.7 if you set the buffer size to zero when calling 
fdopen.

fd = os.open("my_file", os.O_DIRECT | os.O_RDWR)
f = os.fdopen(fd, "rb+", 0)
m = mmap.mmap(-1, 4096)
f.readinto(m)

This is according to a comment in _pyio.py:

# If remaining space in callers buffer is larger than
# internal buffer, read directly into callers buffer

So by simply disabling the buffer (which is what we'd want for O_DIRECT anyway) 
readinto() works as expected. 

However, based on this issue, I'm a little concerned this won't be fully 
supported by python going forward; so use with care.

----------
nosy: +logang

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue5396>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to