ezmsg.tools.shmem.shmem_mirror#
It is possible to move data from ezmsg to non-ezmsg processes using shared memory. This module contains the non-ezmsg half of that communication. The ezmsg half is found in .shmem. The same shmem_name must be passed to both the ShMemCircBuff and the EZShmMirror objects!
Besides the sample data, the mirror exposes the source AxisArray’s static metadata – its coordinate axes (e.g. a ch axis naming each channel), axis units, and attrs – via the axes, attrs, and dims properties. These are plain dicts rather than ezmsg objects; see .aux_meta for why. They read None until the writer publishes, and update in place if it ever republishes, so poll them (or register_metadata_callback) rather than reading once.
Classes
- class EZShmMirror(shmem_name=None)[source]#
Bases:
objectAn object that has a local (in-client-process) representation of the shared memory from another process’ .shmem.ShMemCircBuff Unit.
There are 2 pieces of shared memory: the metadata and the data buffer. The ezmsg node is responsible for creating both pieces. Here we only connect to them. We cannot know if the shared memory exists before we try to connect to it, so we must try the connection – sometimes repeatedly while handling connection errors.
- Parameters:
shmem_name (str | None)
- property meta: ShmemArrMeta | None#
- property axes: Dict[str, dict] | None#
The source AxisArray’s axes as plain dicts, or None if unavailable.
Keyed by axis name. Each value is
{"kind": "linear", "unit", "gain", "offset"}or{"kind": "coord", "unit", "dims", "data"}– seeaux_metafor why these are dicts rather than ezmsg axis objects.The buffered axis (whatever the sink was configured to buffer along, normally
"time") appears here with only its static descriptors: its position along the stream lives in the ring’s write index, not here.None means the writer has not published yet – poll again. A writer this build cannot read raises
ShmemVersionErroron connect rather than showing up as None here.
- property dims: List[str] | None#
The source AxisArray’s dimension names, in the sender’s order.
Note the buffer itself is rolled so the buffered axis comes first; this is the message’s original ordering.
- property stream_dim: str | None#
Which dimension the source declared it accumulates along.
Distinct from the buffered axis: an operator can override that, and a producer on ezmsg < 3.10 declares nothing, in which case this is None.
- register_metadata_callback(callback)[source]#
Call
callbackwhenever a new metadata generation is decoded.Separate from
register_change_callback(), which fires when the data buffer is rebuilt. The two are independent: channel labels can arrive without the buffer changing, and vice versa.- Parameters:
callback (Callable)
- Return type:
None
- class EZShmMirror(shmem_name=None)[source]#
Bases:
objectAn object that has a local (in-client-process) representation of the shared memory from another process’ .shmem.ShMemCircBuff Unit.
There are 2 pieces of shared memory: the metadata and the data buffer. The ezmsg node is responsible for creating both pieces. Here we only connect to them. We cannot know if the shared memory exists before we try to connect to it, so we must try the connection – sometimes repeatedly while handling connection errors.
- Parameters:
shmem_name (str | None)
- property meta: ShmemArrMeta | None#
- property axes: Dict[str, dict] | None#
The source AxisArray’s axes as plain dicts, or None if unavailable.
Keyed by axis name. Each value is
{"kind": "linear", "unit", "gain", "offset"}or{"kind": "coord", "unit", "dims", "data"}– seeaux_metafor why these are dicts rather than ezmsg axis objects.The buffered axis (whatever the sink was configured to buffer along, normally
"time") appears here with only its static descriptors: its position along the stream lives in the ring’s write index, not here.None means the writer has not published yet – poll again. A writer this build cannot read raises
ShmemVersionErroron connect rather than showing up as None here.
- property dims: List[str] | None#
The source AxisArray’s dimension names, in the sender’s order.
Note the buffer itself is rolled so the buffered axis comes first; this is the message’s original ordering.
- property stream_dim: str | None#
Which dimension the source declared it accumulates along.
Distinct from the buffered axis: an operator can override that, and a producer on ezmsg < 3.10 declares nothing, in which case this is None.
- register_metadata_callback(callback)[source]#
Call
callbackwhenever a new metadata generation is decoded.Separate from
register_change_callback(), which fires when the data buffer is rebuilt. The two are independent: channel labels can arrive without the buffer changing, and vice versa.- Parameters:
callback (Callable)
- Return type:
None