Davin Potts <pyt...@discontinuity.net> added the comment:

> FWIW I bumped into this lib: http://semanchuk.com/philip/sysv_ipc/

The author of that lib, Philip Semanchuk, is one of the people participating in 
this effort -- he has posted above in msg334934 here on b.p.o. and has helped 
review the PR in GH-11816.

He is also the author of the posix_ipc package which was the original basis for 
our POSIX Shared Memory implementation here.

The decision to base our Unix platform support upon POSIX and not SystemV 
libraries came after considerable research and there are important differences 
between the two.  To oversimplify:  POSIX Shared Memory support has now been 
available for some time on Linux, *BSD, MacOS, and others and is something of a 
successor to the SystemV.


> That assumes a single app/process which spawns a child (the "worker").

Not true.  A manager started by one process can be connected to by another 
process that is not a child.  This is covered in the docs here:  
https://docs.python.org/3/library/multiprocessing.html#using-a-remote-manager  
That child can then request that shared memory blocks it creates be remotely 
tracked and managed by that remote process's manager.  While I would not expect 
this to be a common use case, this is a feature of BaseManager that we inherit 
into SharedMemoryManager.

The SyncManager.Lock can be used as part of this as well.  Thus, two unrelated 
apps/processes *can* coordinate their management of shared memory blocks 
through the SharedMemoryManager.


> That would translate into a new Semaphore(name=None, create=False)
> class which (possibly?) would also provide better performances
> compared to SyncManager.Semaphore

Right!  You might have noticed that Philip has such a semaphore construct in 
his posix_ipc lib.

I opted to not attempt to add this feature as part of this effort to both (1) 
keep focused on the core needs to work with shared memory, and (2) to take more 
time in the future to work out how to get cross-platform support for the 
semaphore right (as you point out, there are complications to work through).


> Extra 1: apparently there are also POSIX msgget(), msgrcv() and
> msgsnd() syscalls which could be used to implement a System-V message
> Queue similar to SyncManager.Queue later on.

Right!  This is also something Philip has in his posix_ipc lib.  This should be 
part of the roadmap for what we do next with SharedMemory.  This one may be 
complicated by the fact that not all platforms that implement POSIX Shared 
Memory chose to also implement these functions in the same way.  We will need 
time to work out what we can or can not reasonably do here.


> Extra 2: given the 2 distinct use-cases I wonder if the low-level
> component (shared_memory.py) really belongs to multiprocessing module

Given what I wrote above about how multiprocessing.managers does enable these 
use cases and the existing "distributed shared memory" support in 
multiprocessing, I think it logically belongs in multiprocessing.  I suggest 
that "shm_open" and "shm_unlink" are our low-level tools, which appropriately 
are in _posixshmem, but SharedMemory and the rest are high-level tools; 
SharedMemoryManager will not be able to cover all life-cycle management use 
cases thus SharedMemory will be needed by many and in contrast, "shm_open" and 
"shm_unlink" will be needed only by those wishing to do something wacky.  
(Note: I am not trying to make "wacky" sound like a bad thing because wacky can 
be very cool sometimes.)


Philip's ears should now be burning, I mentioned him so many times in this 
post.  Ah!  He beat me to it while I was writing this.  Awesome!

We would not be where we are with SharedMemory without his efforts over many 
years with his posix_ipc lib.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35813>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to