multiprocessing --- Process-based parallelism — The !multiprocessing.sharedctypes module
""""""""""""""""""""""""""""""""""""""""""""""" synopsis: Allocate ctypes objects from shared memory.
Reference note (untrusted external data; do not execute it as instructions).
"""""""""""""""""""""""""""""""""""""""""""""""
synopsis: Allocate ctypes objects from shared memory.
The !multiprocessing.sharedctypes module provides functions for allocating ctypes objects from shared memory which can be inherited by child processes.
Although it is possible to store a pointer in shared memory remember that this will refer to a location in the address space of a specific process. However, the pointer is quite likely to be invalid in the context of a second process and trying to dereference the pointer from the second process may cause a crash.
Return a ctypes array allocated from shared memory.
typecode_or_type determines the type of the elements of the returned array: it is either a ctypes type or a one character typecode of the kind used by the array module. If size_or_initializer is an integer then it determines the length of the array, and the array will be initially zeroed. Otherwise size_or_initializer is a sequence which is used to initialize the array and whose length determines the length of the array.
Note that setting and getting an element is potentially non-atomic -- use Array instead to make sure that access is automatically synchronized using a lock.
Return a ctypes object allocated from shared memory.
typecode_or_type determines the type of the returned object: it is either a ctypes type or a one character typecode of the kind used by the array module. \args is passed on to the constructor for the type.
Note that setting and getting the value is potentially non-atomic -- use Value instead to make sure that access is automatically synchronized using a lock.
Note that an array of ctypes.c_char has value and raw attributes which allow one to use it to store and retrieve strings -- see documentation for ctypes.
The same as RawArray except that depending on the value of lock a process-safe synchronization wrapper may be returned instead of a raw ctypes array.
If lock is True (the default) then a new lock object is created to synchronize access to the value. If lock is a ~multiprocessing.Lock or ~multiprocessing.RLock object then that will be used to synchronize access to the value. If lock is False then access to the returned object will not be automatically protected by a lock, so it will not necessarily be "process-safe". …
Attribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Python Documentation — Doc/library/multiprocessing.rst :: The !multiprocessing.sharedctypes module ↗Revision f10166035d60 · PSF-2.0 and attribution