Skip to content

Conversation

@achimnol
Copy link
Member

Summary

  • Add support for injecting an external zmq.asyncio.Context through transport_opts["zctx"]
  • When an external context is provided, it will not be destroyed when the transport is closed
  • Add CLAUDE.md for development environment guide

Motivation

Applications using callosum may want to share a single ZMQ context across multiple Peer instances throughout the application lifecycle. This reduces resource overhead and follows ZMQ best practices of using one context per application.

Changes

  • ZeroMQBaseTransport.__init__(): Check for transport_opts["zctx"] and use it if provided
  • ZeroMQBaseTransport.close(): Skip context.destroy() for externally injected contexts
  • Added tests for both external and internal context lifecycle management

Usage

import zmq.asyncio

# Application-wide context
app_zctx = zmq.asyncio.Context()

peer = Peer(
    bind=ZeroMQAddress("tcp://127.0.0.1:5020"),
    transport=ZeroMQRPCTransport,
    transport_opts={"zctx": app_zctx},
    ...
)

# Application is responsible for cleanup
app_zctx.destroy(linger=100)

Test plan

  • test_external_context_injection: Verifies external context is used and not destroyed on close
  • test_internal_context_destroyed_on_close: Verifies internal context is destroyed on close

…ort_opts

Add support for injecting an external zmq.asyncio.Context through
transport_opts["zctx"]. This enables applications to share a single
context across multiple Peer instances throughout the application
lifecycle, reducing resource overhead.

When an external context is provided, it will not be destroyed when
the transport is closed - the application is responsible for managing
its lifecycle.
@achimnol achimnol merged commit e12ebe4 into main Jan 22, 2026
15 checks passed
@achimnol achimnol deleted the feat/allow-using-external-zmq-context branch January 22, 2026 06:00
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