[New-bugs-announce] [issue12102] mmap requires file to be synced

rion report at bugs.python.org
Wed May 18 11:56:04 CEST 2011


New submission from rion <rion4ik at gmail.com>:

Not flushed file gives next results:

rion at rionhost ~/temp $ python2 test.py 
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
mmap.error: [Errno 22] Invalid argument
rion at rionhost ~/temp $ python3 test.py 
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
ValueError: mmap offset is greater than file size


testcase:

import mmap
from tempfile import TemporaryFile

f = TemporaryFile()
f.write(b"hello world")

#f.flush()

m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)


just uncomment f.flush() and try again. feel the difference.

suggestion: force flush on file descriptor when passed to mmap.

----------
components: None
messages: 136217
nosy: rion4ik at gmail.com
priority: normal
severity: normal
status: open
title: mmap requires file to be synced
type: behavior
versions: Python 2.7, Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12102>
_______________________________________


More information about the New-bugs-announce mailing list