I defined a ShareableList()
to store strings in it by using the following code:
from multiprocessing import shared_memory
global_memory = shared_memory.ShareableList([""] * 10, name='my_mem')
global_memory[0] = "hello I'm a long string"
It returns:
ValueError: bytes/str item exceeds available storage
I expected this because in the documentation example the same happened:
>>> from multiprocessing import shared_memory
>>> a = shared_memory.ShareableList(['howdy', b'HoWdY', -273.154, 100, None, True, 42])
>>> [ type(entry) for entry in a ]
[<class 'str'>, <class 'bytes'>, <class 'float'>, <class 'int'>, <class 'NoneType'>, <class 'bool'>, <class 'int'>]
>>> a[2]
-273.154
>>> a[2] = -78.5
>>> a[2]
-78.5
>>> a[2] = 'dry ice' # Changing data types is supported as well
>>> a[2]
'dry ice'
>>> a[2] = 'larger than previously allocated storage space'
Traceback (most recent call last):
...
ValueError: exceeds available storage for existing str
>>> a[2]
'dry ice'
len(a)
7
a.index(42)
6
a.count(b'howdy')
0
a.count(b'HoWdY')
1
a.shm.close()
a.shm.unlink()
del a # Use of a ShareableList after call to unlink() is unsupported
But my question is, how to add more space for every element in the list, so I can store larger strings?
Thanks in advance.
question from:
https://stackoverflow.com/questions/65858251/how-to-set-the-size-of-shareablelist-list-in-multiprocessing-shared-memory 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…