Weird error when trying to write to an mmap under windows
Question: This simple python code:

    
    
    import mmap  
    
    with file("o:/temp/mmap.test", "w+b") as fp:  
        m = mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ|mmap.ACCESS_WRITE)  
        m.write("Hello world!")  
    

Produces the following error (on the mmap.mmap(...) line):  
WindowsError: [Error 1006] The volume for a file has been externally altered
so that the opened file is no longer valid

Any idea why?


Answer: Most likely because `w+` truncates the file, and Windows gives an error when
trying to create an empty mapping from that file of length 0. Use `r+`
instead.

As well, you shouldn't use `access=mmap.ACCESS_READ|mmap.ACCESS_WRITE`:

    
    
    >>> mmap.ACCESS_READ
    1
    >>> mmap.ACCESS_WRITE
    2
    >>> mmap.ACCESS_COPY
    3
    >>> mmap.ACCESS_READ | mmap.ACCESS_WRITE
    3
    

In other words, `access=mmap.ACCESS_READ|mmap.ACCESS_WRITE` is the same as
`access=mmap.ACCESS_COPY`. What you want is most likely
`access=mmap.ACCESS_WRITE`, and on Windows that's what you get anyway if you
don't explicitly use that argument.

Try this:

    
    
    import mmap  
    
    with file("o:/temp/mmap.test", "r+b") as fp:  
        m = mmap.mmap(fp.fileno(), 0)  
        m.write("Hello world!")  
    

( mmap docs: <http://docs.python.org/library/mmap.html> )

