Skip to content
GitHub · 2.7.0

Guides

Publish a data stream

Use an outlet to publish numbers for another application to read.

Construct an output in main(), keep a reference and call .push(data) from @pipeline.predict. Outputs are user-owned and are not registered with the app. Outlet runs a daemon thread at your hz that sends whatever was last pushed.

Writing one

  1. Subclass Outlet.
  2. Open your socket, file or channel first, then call super().__init__(hz=...) last. The send thread starts inside that call, so a resource opened after it can be read before it exists.
  3. Implement _send(self, data) -> None, the actual transport call. Treat data as read-only and validate its shape.
  4. Override stop() if you hold a resource, calling super().stop() first.

Worked example: a telemetry socket

Numbers to a dashboard on another host.

Python
import socket
import numpy as np
from myogestic.outputs import Outlet
class TelemetryOutlet(Outlet):
"""Send the latest prediction vector to a dashboard as float32 datagrams."""
def __init__(self, host: str, port: int, hz: float = 20.0):
# Socket first: `super().__init__` starts the send thread.
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self._addr = (host, port)
super().__init__(hz=hz)
def _send(self, data: np.ndarray) -> None:
self._sock.sendto(data.astype(np.float32).tobytes(), self._addr)
def stop(self) -> None:
super().stop()
self._sock.close()

Use it:

Python
telemetry = TelemetryOutlet("127.0.0.1", 9000, hz=20)
app.cleanup_hooks.append(lambda _app: telemetry.stop())
@pipeline.predict
def predict(model, features):
pose = model.predict(features)
telemetry.push(pose)
return {"pose": pose}

push is non-blocking. _send runs every 1/hz on the output’s own thread, so transport latency never reaches the predict loop.

Choosing hz

Match hz to the consumer’s input rate rather than the predict rate. A dashboard redrawing at 20 Hz gains nothing from 200. If you push faster than hz, only the latest value is sent; if you push slower, the same value is sent again. This latest-wins policy spends bandwidth on repeats without changing their value.

Common mistakes

See Troubleshooting for errors by symptom.

  • Driving a device with one. No clamp, no aliases, and the transport closes while the device still holds the last thing it was told. That is a target.
  • Heavy work inside _send. It runs at hz; longer than 1/hz and the thread falls behind. Keep it non-blocking, or lower hz.
  • Calling _send from predict(). Blocks predict on transport latency. Go through push.
  • Assuming push(...) delivers everything. Delivery is fire-and-forget through a latest-value slot. Push twice between ticks and only the second value is sent. Do not use it for events; use a queue.