Feature: Synchronous Low‑Level API for ezmsg (ROS2‑style ergonomics)#215
Open
griffinmilsap wants to merge 3 commits intodevfrom
Open
Feature: Synchronous Low‑Level API for ezmsg (ROS2‑style ergonomics)#215griffinmilsap wants to merge 3 commits intodevfrom
griffinmilsap wants to merge 3 commits intodevfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SyncContext,SyncPublisher,SyncSubscriber,init,spin,spin_once) so users can publish/subscribe without asyncio.GraphContext(auto_start=...)andGraphService.ensure(auto_start=...).Motivation
Many users find
asynciointimidating; the goal is to let them use ezmsg with a simple, synchronous API similar to ROS2 (with ez.sync.init(...),spin(),spin_once()), while preserving ezmsg’s backpressure semantics and zero‑copy safety.This wrapper is explicitly for ergonomics, not peak throughput.
Implementation Details
New Sync API (
src/ezmsg/core/sync.py)GraphContextand runs an asyncio event loop in a background thread usingnew_threaded_event_loop.create_publisher/create_subscriptioncall the underlying async API viaasyncio.run_coroutine_threadsafe.spin()/spin_once()pull messages directly viarecv_zero_copy()and only release backpressure after the user callback returns.spin_once()returns a boolean for “did work”.GraphServer Auto‑Start Control
GraphService.ensure(auto_start: bool | None = None)Nonepreserves existing “auto‑start only when address is not specified + no env override.”True/Falseoverrides.GraphContext(..., auto_start=...)passes through toGraphService.ensure.ez.sync.init(..., auto_start=...)mirrorsGraphContextdefaulting toNone.Examples
examples/simple_publisher.pyexamples/simple_subscriber.pyexamples/simple_async_publisher.pyexamples/simple_async_subscriber.pyTests
tests/test_sync_api.pyPerf Script
tests/perf_sync_overhead.pyThreads and Concurrency Model
spin,spin_once, callbacks).publish()/recv()call crosses threads viarun_coroutine_threadsafe.Performance
Measured using
tests/perf_sync_overhead.py(local macOS example):Interpretation:
Files Changed / Added
src/ezmsg/core/sync.pysrc/ezmsg/core/__init__.pysrc/ezmsg/core/graphcontext.pysrc/ezmsg/core/graphserver.pyexamples/simple_publisher.pyexamples/simple_subscriber.pyexamples/simple_async_publisher.pyexamples/simple_async_subscriber.pytests/test_sync_api.pytests/perf_sync_overhead.pyexamples/lowlevel.py(replaced by split examples)