[Python-ideas] Adding shm_open to mmap?

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Feb 16 02:56:22 CET 2012


On 16/02/12 06:43, shibturn wrote:

> A process which creates an mmap may want to transfer ownership of the mmap to
> another process along a pipeline. For example:
>
> 1) Process A creates an mmap
> 2) Process A does some work on mmap
> 3) Process A puts mmap on a queue.
> 4) mmap gets garbage collected in process A.
> 5) Process B gets mmap from queue.

I don't know about Windows, but in Unix it's possible to send a
file descriptor from one process to another over a unix-domain
socket connection. So a refcounted anonymous mmap handover could
be achieved this way:

1. Process A creates a temp file, mmaps it and unlinks it.
2. Process A sends the file descriptor to process B over a
    unix-domain socket.
3. Process B mmaps it.

Even if process A closes its version of the fd right after
sending it, the OS should keep it alive while it's in transit,
I think.

-- 
Greg



More information about the Python-ideas mailing list