Usage¶
CPU stream quickstart¶
import numpy as np
import pyshmem
writer = pyshmem.create("frames", shape=(480, 640), dtype=np.float32)
reader = pyshmem.open("frames")
writer.write(np.ones((480, 640), dtype=np.float32))
frame = reader.read()
GPU stream quickstart¶
import numpy as np
import pyshmem
writer = pyshmem.create(
"activations",
shape=(1024, 1024),
dtype=np.float32,
gpu_device="cuda:0",
)
reader = pyshmem.open("activations", gpu_device="cuda:0")
writer.write(np.ones((1024, 1024), dtype=np.float32))
activation = reader.read()
Reading modes¶
read(safe=True) returns a consistent snapshot of the latest completed write.
read(safe=False) exposes the live backing storage and therefore requires the
caller to hold the stream lock first.
with reader.locked():
raw = reader.read(safe=False)
Waiting for the next write¶
Use read_new when you want to block until a new payload arrives.
next_frame = reader.read_new(timeout=1.0)
Lifecycle¶
close()releases only the current handleunlink()destroys the shared-memory streamdelete()is an alias forunlink()
Be conservative with unlink() in multi-process systems: any attached handle
can destroy the stream.