New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mmap resize fails on anonymous memory #46985
Comments
We have a shared memory module that has been running fine on Windows
with Active State Python 2.4.3 Build 12. On machines with 2.5.1.1
mmap.resize fails on an existing anonymous shared memory. The attached
file is a stripped down version of the code to illustrate the problem.
Start it running in one window to create the shared memory, then in
another window run it again to hook into existing shared memory. Result:
Testing SharedMemory
open -self.memory_size 336
Traceback (most recent call last):
File "C:/home/weather/TESTOF~1.PY", line 164, in <module>
example()
File "C:/home/weather/TESTOF~1.PY", line 147, in example
sm = SharedMemory( 'my_shared_memory')
File "C:/home/weather/TESTOF~1.PY", line 31, in __init__
self.__open()
File "C:/home/weather/TESTOF~1.PY", line 94, in __open
self.memory.resize(self.memory_size)
WindowsError: [Error 8] Not enough storage is available to process this
command |
It seems that you attached the output file instead of a python script... |
sorry |
OK, I can see why this is happening and in fact there are two levels of (References to mmapmodule.c at r69666) Problem 1: At line 456, the CreateFileMapping call is made with 0 hi/lo Problem 2: The call to SetFilePointer at line 451 passes the hi/lo size I'm not entirely sure what the SetFilePointer call is achieving at this |
Patch attached to mmapmodule.c and test_mmap.py |
Tim, I confirmed your test fails on my machine, and is fixed by your patch. |
From me, yes of course, but I assume you want another |
I reconsidered this issue. When mmap is anonymous, And the behavior of mmap.resize is not documented clearly though, >>> import mmap
>>> m1 = mmap.mmap(-1, 10, tagname="foo")
>>> m2 = mmap.mmap(-1, 10, tagname="foo")
>>> for i in xrange(10):
... m1[i] = str(i)
...
>>> m1[:]
'0123456789'
>>> m2[:]
'0123456789'
>>> m2.resize(5)
>>> m1[:]
'0123456789'
>>> m2[:]
'01234' For file mapping object, mmap.resize() resizes underlying file too, but |
Hirokazu Yamamoto wrote:
I'm inclined to agree. I must admit, I was pushing a change
I have no strong opinion myself. In reality I rarely use mmaps; I'm not sure who's best placed to decide what |
More two cents which I noticed. (After the patch was applied)
>>> import mmap
>>> m = mmap.mmap(-1, 10)
>>> m[:] = "0123456789"
>>> m[:]
'0123456789'
>>> m.resize(20)
>>> m[:]
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
0'
Sorry for having clear solution for this. But I cannot say "This is what |
|
I still think we should forbid to resize anonymous memory map because Here is a patch for it. |
I don't see an actual crash reported. An unexpected exception is not a crash. Changing the type to "behavior". |
I wonder if this is related to the problem I reported about two weeks ago |
https://bugs.python.org/issue40915 is related |
Superseded by bpo-40915 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: