MCPcopy Index your code
hub / github.com/RustPython/RustPython / __init__

Method __init__

Lib/multiprocessing/shared_memory.py:308–379  ·  view source on GitHub ↗
(self, sequence=None, *, name=None)

Source from the content-addressed store, hash-verified

306 return 3 # NoneType
307
308 def __init__(self, sequence=None, *, name=None):
309 if name is None or sequence is not None:
310 sequence = sequence or ()
311 _formats = [
312 self._types_mapping[type(item)]
313 if not isinstance(item, (str, bytes))
314 else self._types_mapping[type(item)] % (
315 self._alignment * (len(item) // self._alignment + 1),
316 )
317 for item in sequence
318 ]
319 self._list_len = len(_formats)
320 assert sum(len(fmt) <= 8 for fmt in _formats) == self._list_len
321 offset = 0
322 # The offsets of each list element into the shared memory's
323 # data area (0 meaning the start of the data area, not the start
324 # of the shared memory area).
325 self._allocated_offsets = [0]
326 for fmt in _formats:
327 offset += self._alignment if fmt[-1] != "s" else int(fmt[:-1])
328 self._allocated_offsets.append(offset)
329 _recreation_codes = [
330 self._extract_recreation_code(item) for item in sequence
331 ]
332 requested_size = struct.calcsize(
333 "q" + self._format_size_metainfo +
334 "".join(_formats) +
335 self._format_packing_metainfo +
336 self._format_back_transform_codes
337 )
338
339 self.shm = SharedMemory(name, create=True, size=requested_size)
340 else:
341 self.shm = SharedMemory(name)
342
343 if sequence is not None:
344 _enc = _encoding
345 struct.pack_into(
346 "q" + self._format_size_metainfo,
347 self.shm.buf,
348 0,
349 self._list_len,
350 *(self._allocated_offsets)
351 )
352 struct.pack_into(
353 "".join(_formats),
354 self.shm.buf,
355 self._offset_data_start,
356 *(v.encode(_enc) if isinstance(v, str) else v for v in sequence)
357 )
358 struct.pack_into(
359 self._format_packing_metainfo,
360 self.shm.buf,
361 self._offset_packing_formats,
362 *(v.encode(_enc) for v in _formats)
363 )
364 struct.pack_into(
365 self._format_back_transform_codes,

Callers

nothing calls this directly

Calls 11

isinstanceFunction · 0.85
lenFunction · 0.85
SharedMemoryClass · 0.85
listClass · 0.85
unpack_fromMethod · 0.80
sumFunction · 0.50
appendMethod · 0.45
joinMethod · 0.45
pack_intoMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected