Concurrency and Process Modules

multiprocessing.shared_memory

Named shared memory blocks allow processes on one machine to access common bytes. Access via a memoryview; coordinate writers separately. Each handle must close and the block must be unlinked once when no longer needed, subject to OS lifetime rules. Python 3.13 adds the track parameter. This example uses a tiny local block.

Formal Syntax & Structure

python syntaxpython
import multiprocessing.shared_memory

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
from multiprocessing.shared_memory import SharedMemoryblock = SharedMemory(create=True, size=4)try:    block.buf[:4] = b"data"    print(bytes(block.buf[:4]))finally:    block.close()    block.unlink()
Python Reference