Skip to content

Commit 3d2ba4b

Browse files
tkrenpitrou
authored andcommitted
Improve readability
Always use a list for storing the sequence of running allocated bytes in ShareableList._allocated_bytes
1 parent 0c45dc6 commit 3d2ba4b

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

Lib/multiprocessing/shared_memory.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,11 @@ def __init__(self, sequence=None, *, name=None):
294294
]
295295
self._list_len = len(_formats)
296296
assert sum(len(fmt) <= 8 for fmt in _formats) == self._list_len
297-
sum_allocated_bytes = 0
298-
self._allocated_bytes = tuple(
299-
(sum_allocated_bytes := sum_allocated_bytes + (
300-
self._alignment if fmt[-1] != "s" else int(fmt[:-1])
301-
)
302-
)
303-
for fmt in _formats
304-
)
297+
offset = 0
298+
self._allocated_bytes = []
299+
for fmt in _formats:
300+
offset += self._alignment if fmt[-1] != "s" else int(fmt[:-1])
301+
self._allocated_bytes.append(offset)
305302
_recreation_codes = [
306303
self._extract_recreation_code(item) for item in sequence
307304
]
@@ -350,10 +347,12 @@ def __init__(self, sequence=None, *, name=None):
350347

351348
else:
352349
self._list_len = len(self) # Obtains size from offset 0 in buffer.
353-
self._allocated_bytes = struct.unpack_from(
354-
self._format_size_metainfo,
355-
self.shm.buf,
356-
1 * 8
350+
self._allocated_bytes = list(
351+
struct.unpack_from(
352+
self._format_size_metainfo,
353+
self.shm.buf,
354+
1 * 8
355+
)
357356
)
358357

359358
def _get_packing_format(self, position):

0 commit comments

Comments
 (0)