bpo-41344: Raise ValueError when creating shared memory of size 0 (GH… · python/cpython@38e3287 · GitHub
Skip to content

Commit 38e3287

Browse files
bpo-41344: Raise ValueError when creating shared memory of size 0 (GH-21556) (GH-22019)
(cherry picked from commit 475a5fb) Co-authored-by: Vinay Sharma <vinay04sharma@icloud.com> Co-authored-by: Vinay Sharma <vinay04sharma@icloud.com>
1 parent 85ca9c0 commit 38e3287

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

Lib/multiprocessing/shared_memory.py

Lines changed: 2 additions & 0 deletions

Lib/test/_test_multiprocessing.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,6 +3827,18 @@ class OptionalAttachSharedMemory(shared_memory.SharedMemory):
38273827

38283828
sms.close()
38293829

3830+
# Test creating a shared memory segment with negative size
3831+
with self.assertRaises(ValueError):
3832+
sms_invalid = shared_memory.SharedMemory(create=True, size=-1)
3833+
3834+
# Test creating a shared memory segment with size 0
3835+
with self.assertRaises(ValueError):
3836+
sms_invalid = shared_memory.SharedMemory(create=True, size=0)
3837+
3838+
# Test creating a shared memory segment without size argument
3839+
with self.assertRaises(ValueError):
3840+
sms_invalid = shared_memory.SharedMemory(create=True)
3841+
38303842
def test_shared_memory_across_processes(self):
38313843
# bpo-40135: don't define shared memory block's name in case of
38323844
# the failure when we run multiprocessing tests in parallel.
Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)