lcm - Lightweight Communication and Marshalling
raw JSON → 1.5.2 verified Mon Apr 27 auth: no python
lcm (Lightweight Communication and Marshalling) is a library for interprocess communication with real-time constraints, providing a low-latency publish/subscribe message passing model. Version 1.5.2 supports Python >=3.7. Release cadence is irregular, typically yearly.
pip install lcm Common errors
error ModuleNotFoundError: No module named 'lcm' ↓
cause lcm not installed or installed in wrong environment.
fix
Run: pip install lcm
error AttributeError: module 'lcm' has no attribute 'LCM' ↓
cause Imported as 'import lcm' instead of 'from lcm import LCM'.
fix
Use: from lcm import LCM
error OSError: [Errno 19] No such device ↓
cause LCM tries to open multicast socket but network interface doesn't support multicast or is missing.
fix
Check network configuration, or use LCM with a directed UDP address. On Linux, ensure multicast is enabled: sudo apt-get install net-tools && route -n
Warnings
gotcha lcm requires a running LCM daemon (lcm-logger or similar) or multicast network. Without it, publish/subscribe silently fails. ↓
fix Ensure LCM daemon is running or network multicast is configured. Test with lcm-spy or a simple sender/receiver.
gotcha The LCM class is not thread-safe. Calling methods from multiple threads can cause undefined behavior. ↓
fix Use locking mechanisms or ensure all LCM calls happen from a single thread.
gotcha LCM messages are raw bytes; data serialization is left to the user. There's no built-in type marshalling beyond bytes. ↓
fix Use struct.pack/unpack, protobuf, or similar for structured data. Example: data = struct.pack('i', 42).
Imports
- LCM wrong
import lcmcorrectfrom lcm import LCM - EventLog
from lcm import EventLog
Quickstart
from lcm import LCM
lc = LCM()
def handler(channel, data):
print(f"Received on {channel}: {data}")
lc.subscribe("EXAMPLE_CHANNEL", handler)
lc.handle()
lc.publish("EXAMPLE_CHANNEL", b"Hello, world!")