New submission from Davin Potts <pyt...@discontinuity.net>:

The resource tracker currently destroys (via _posixshmem.shm_unlink) shared 
memory segments on posix systems when any independently created Python process 
with a handle on a shared memory segment exits (gracefully or otherwise).  This 
breaks the expected cross-platform behavior that a shared memory segment 
persists at least as long as any running process has a handle on that segment.

As described with an example scenario in issue37754:
Let's say a three processes P1, P2 and P3 are trying to communicate using 
shared memory.
 --> P1 creates the shared memory block, and waits for P2 and P3 to access it.
 --> P2 starts and attaches this shared memory segment, writes some data to it 
and exits.
 --> Now in case of Unix, shm_unlink is called as soon as P2 exits. (This is by 
action of the resource tracker.)
 --> Now, P3 starts and tries to attach the shared memory segment.
 --> P3 will not be able to attach the shared memory segment in Unix, because 
shm_unlink has been called on that segment.
 --> Whereas, P3 will be able to attach to the shared memory segment in Windows.

Another key scenario we expect to work but does not currently:
1. A multiprocessing.managers.SharedMemoryManager is instantiated and started 
in process A.
2. A shared memory segment is created using that manager in process A.
3. A serialized representation of that shared memory segment is deserialized in 
process B.
4. Process B does work with the shared memory segment that is also still 
visible to process A.
5. Process B exits cleanly.
6. Process A reads data from the shared memory segment after process B is gone. 
 (This currently fails.)

The SharedMemoryManager provides a flexible means for ensuring cleanup of 
shared memory segments.  The current resource tracker attempts to treat shared 
memory segments as equivalent to semaphore references, which is too narrow of 
an interpretation.  As such, the current resource tracker should not be 
attempting to enforce cleanup of shared memory segments because it breaks 
expected behavior and significantly limits functionality.

----------
assignee: davin
components: Library (Lib)
messages: 351960
nosy: davin, pablogsal, pitrou, vinay0410, vstinner
priority: normal
severity: normal
status: open
title: resource tracker destroys shared memory segments when other processes 
should still have valid access
type: behavior
versions: Python 3.8, Python 3.9

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

Reply via email to