[Python-ideas] Adding shm_open to mmap?

shibturn shibturn at gmail.com
Wed Feb 15 02:00:30 CET 2012


On 15/02/2012 12:05am, Antoine Pitrou wrote:
 > A patch is enough.
 >
 > Note that this functionality is already available under Windows
 > (though not really advertised in our docs), through the `tagname`
 > parameter to mmap.mmap():
 >
 >>>> import mmap
 >>>> f = mmap.mmap(-1, 4096, "mysharedmem")
 >>>> f.write(b"some bytes")
 >
 > And in another session:
 >
 >>>> import mmap
 >>>> f = mmap.mmap(-1, 4096, "mysharedmem")
 >>>> f.read(10)
 > b'some bytes'
It's not quite the same functionality since the lifetime of tagnamed 
mmaps is managed through handle refcounting. In some cases that is an 
advantage compared to open()/unlink(), and in others a disadvantage.
Also, a problem with tagname is that there is no way to check whether 
the returned mmap was created by another process -- unless you resort to 
something like undocumented like
 from _multiprocessing import win32
 f = mmap.mmap(-1, 4096, "mysharedmem")
 if win32.GetLastError() == win32.ERROR_ALREADY_EXISTS:
 raise ValueError('tagname already exists')
sbt


More information about the Python-ideas mailing list

AltStyle によって変換されたページ (->オリジナル) /