@@ -255,16 +255,17 @@ shared memory blocks created using that manager are all released when the
255
255
:keyword: `with ` statement's code block finishes execution.
256
256
257
257
258
- .. class :: ShareableList(sequence=None, *, name=None)
258
+ .. class :: ShareableList(sequence=None, \ *, name=None)
259
259
260
260
Provides a mutable list-like object where all values stored within are
261
261
stored in a shared memory block. This constrains storable values to
262
- only the ``int ``, ``float ``, ``bool ``, ``str `` (less than 10M bytes each),
263
- ``bytes `` (less than 10M bytes each), and ``None `` built-in data types.
264
- It also notably differs from the built-in ``list `` type in that these
265
- lists can not change their overall length (i.e. no append, insert, etc.)
266
- and do not support the dynamic creation of new :class: `ShareableList `
267
- instances via slicing.
262
+ only the ``int `` (signed 64-bit), ``float ``, ``bool ``, ``str `` (less
263
+ than 10M bytes each when encoded as utf-8), ``bytes `` (less than 10M
264
+ bytes each), and ``None `` built-in data types. It also notably
265
+ differs from the built-in ``list `` type in that these lists can not
266
+ change their overall length (i.e. no append, insert, etc.) and do not
267
+ support the dynamic creation of new :class: `ShareableList ` instances
268
+ via slicing.
268
269
269
270
*sequence * is used in populating a new ``ShareableList `` full of values.
270
271
Set to ``None `` to instead attach to an already existing
@@ -275,6 +276,35 @@ shared memory blocks created using that manager are all released when the
275
276
existing ``ShareableList ``, specify its shared memory block's unique
276
277
name while leaving ``sequence `` set to ``None ``.
277
278
279
+ .. note ::
280
+
281
+ A known issue exists for :class: `bytes ` and :class: `str ` values.
282
+ If they end with ``\x00 `` nul bytes or characters, those may be
283
+ *silently stripped * when fetching them by index from the
284
+ :class: `ShareableList `. This ``.rstrip(b'\x00') `` behavior is
285
+ considered a bug and may go away in the future. See :gh: `106939 `.
286
+
287
+ For applications where rstripping of trailing nulls is a problem,
288
+ work around it by always unconditionally appending an extra non-0
289
+ byte to the end of such values when storing and unconditionally
290
+ removing it when fetching:
291
+
292
+ .. doctest ::
293
+
294
+ >>> from multiprocessing import shared_memory
295
+ >>> nul_bug_demo = shared_memory.ShareableList([' ?\x00 ' , b ' \x03\x02\x01\x00\x00\x00 ' ])
296
+ >>> nul_bug_demo[0 ]
297
+ '?'
298
+ >>> nul_bug_demo[1 ]
299
+ b'\x03\x02\x01'
300
+ >>> nul_bug_demo.shm.unlink()
301
+ >>> padded = shared_memory.ShareableList([' ?\x00\x07 ' , b ' \x03\x02\x01\x00\x00\x00\x07 ' ])
302
+ >>> padded[0 ][:- 1 ]
303
+ '?\x00'
304
+ >>> padded[1 ][:- 1 ]
305
+ b'\x03\x02\x01\x00\x00\x00'
306
+ >>> padded.shm.unlink()
307
+
278
308
.. method :: count(value)
279
309
280
310
Returns the number of occurrences of ``value ``.
0 commit comments