Skip to content

Add a Python multithread (INTERTHREAD) example - #50

Merged
tsaubergine merged 1 commit into
mainfrom
claude/interthread-python-wrapper-r75m1y
Sep 10, 2026
Merged

tsaubergine merged 1 commit into
mainfrom
claude/interthread-python-wrapper-r75m1y

Conversation

@tsaubergine

Copy link
Copy Markdown
Member

The Python counterpart of the Julia multithread example added in #47, in src/interprocess/zeromq/python/basic_multithread.

A publisher thread produces NavigationReports on the interthread layer, a watcher thread consumes them and forwards each one to interprocess, and the application prints an alert when the vehicle is deep.

What it shows

The example is built around the three consequences of the layer being implemented in Python rather than through the C++ InterThreadTransporter:

  • The application is a SingleThreadApplication. The C++ side never sees these threads, so MultiThreadApplication is not needed.
  • The interthread groups are plain strings named in multithread.py rather than declarations in interface.yml — nothing is generated for the layer, so there is nothing to declare. Only the interprocess publication is in the interface file.
  • An interthread message is any Python object. The depth alert is a dataclass and never becomes protobuf.

The watcher publishes to interprocess from its own thread, which is handed to the application behind the scenes, the way a C++ thread's InterProcessForwarder hands its traffic to the portal. Julia raises an AssertionError in that position.

interface.yml declares the publication on groups::nav with protobuf::NavigationReport, the same group and message the C++ examples use, so goby3_example_basic_interprocess_subscriber in the launch file receives what the watcher forwards.

Files

  • multithread.py, interface.yml, multithread_config.proto, CMakeLists.txt
  • launch/interprocess/zeromq/python_multithread.launch
  • a README section, and the new subdirectory wired into src/interprocess/zeromq/python/CMakeLists.txt

Testing

Ran the example's own classes against stand-in bindings, with src/messages/nav.proto compiled by protoc:

Alerting below 300.0 m
--- serviced at 10.0 Hz while the application asked for none
[publisher] Tx: z=-300.0
[watcher] Rx: z=-300.0
[publisher] Tx: z=-305.0
[watcher] Rx: z=-305.0
[main] alert: 305.0 m at x=99.0 y=198.0
--- forwarded to interprocess: 2 on group groups::nav

Both hops carry, the dataclass crosses interthread intact, the -300.0 report correctly does not trip the 300 m threshold, and the application is serviced at 10 Hz without having asked for a loop frequency. The generated module was also checked against the example's imports: it exports SingleThreadApplication, Thread and groups.nav, with interthread() coming from goby.Thread rather than from any declaration.

Merge order

This needs the Python interthread support in GobySoft/goby3#415. CI here installs libgoby3-dev/python3-goby3 from the continuous packages, which track goby3 3.0, and builds without running, so this example builds today but does not run until #415 is merged and those packages rebuild. Merge #415 first.

🤖 Generated with Claude Code

https://claude.ai/code/session_01D97Q5zTpLKwkDTYQzPRiCX


Generated by Claude Code

The Python counterpart of the Julia multithread example: a publisher thread
produces NavigationReports on the interthread layer, a watcher thread consumes
them and forwards each one to interprocess, and the application prints an alert
when the vehicle is deep.

The example is built around the three consequences of the layer being
implemented in Python: the application is a SingleThreadApplication because the
C++ side never sees these threads, the interthread groups are plain strings
rather than declarations in interface.yml, and the depth alert is a dataclass
that never becomes protobuf. The watcher publishes to interprocess from its own
thread, which is handed to the application behind the scenes.

Requires the Python interthread support in GobySoft/goby3#415, so it builds
today but does not run until that is in the continuous packages.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D97Q5zTpLKwkDTYQzPRiCX
@tsaubergine
tsaubergine merged commit c86a170 into main Sep 10, 2026
6 checks passed
@tsaubergine
tsaubergine deleted the claude/interthread-python-wrapper-r75m1y branch September 10, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants