File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,20 @@ def _make_filename():
49
49
50
50
51
51
class SharedMemory :
52
+ """Creates a new shared memory block or attaches to an existing
53
+ shared memory block.
54
+
55
+ Every shared memory block is assigned a unique name. This enables
56
+ one process to create a shared memory block with a particular name
57
+ so that a different process can attach to that same shared memory
58
+ block using that same name.
59
+
60
+ As a resource for sharing data across processes, shared memory blocks
61
+ may outlive the original process that created them. When one process
62
+ no longer needs access to a shared memory block that might still be
63
+ needed by other processes, the close() method should be called.
64
+ When a shared memory block is no longer needed by any process, the
65
+ unlink() method should be called to ensure proper cleanup."""
52
66
53
67
# Defaults; enables close() and unlink() to run without errors.
54
68
_name = None
Original file line number Diff line number Diff line change @@ -3650,6 +3650,11 @@ def test_shared_memory_basics(self):
3650
3650
self .assertEqual (also_sms .buf [0 ], 42 )
3651
3651
also_sms .close ()
3652
3652
3653
+ # Attach to existing shared memory segment but specify a new size.
3654
+ same_sms = shared_memory .SharedMemory ('test01_tsmb' , size = 20 * sms .size )
3655
+ self .assertEqual (same_sms .size , sms .size ) # Size was ignored.
3656
+ same_sms .close ()
3657
+
3653
3658
if shared_memory ._USE_POSIX :
3654
3659
# Posix Shared Memory can only be unlinked once. Here we
3655
3660
# test an implementation detail that is not observed across
@@ -3675,9 +3680,6 @@ def test_shared_memory_basics(self):
3675
3680
finally :
3676
3681
sms_uno .unlink () # A second shm_unlink() call is bad.
3677
3682
3678
- # Enforcement of `mode` and `read_only` is OS platform dependent
3679
- # and as such will not be tested here.
3680
-
3681
3683
with self .assertRaises (FileExistsError ):
3682
3684
# Attempting to create a new shared memory segment with a
3683
3685
# name that is already in use triggers an exception.
You can’t perform that action at this time.
0 commit comments