LocalServiceAdvertisement¶
- class bpod_core.ipc.LocalServiceAdvertisement ¶
Bases:
AbstractContextManagerFile-based local service advertisement for IPC discovery.
Advertises a service by writing a JSON file to the user’s runtime directory. This provides a lightweight alternative to Zeroconf for discovering services on the same machine. Stale advertisements (from dead processes) are automatically cleaned up during discovery.
The advertisement is automatically removed when the instance is garbage collected or when
close()is called explicitly.- Parameters:
service_name (
str) – The name of the service being advertised (e.g., ‘Bpod 3’).service_type (
str) – The type of service being advertised (e.g., ‘bpod’).address (
str) – The address where the service can be reached (e.g., ‘ipc:///tmp/foo.ipc’).properties (
dict, optional) – Additional key-value properties to advertise with the service.pid (
int, optional) – Process ID of the service. Used to detect stale advertisements.uuid (
UUID, optional) – Unique identifier for this service instance. Generated if not provided.
Examples
Advertise a service:
>>> ad = LocalServiceAdvertisement('Bpod1', 'bpod', 'tcp://127.0.0.1:5555')Discover advertised services:
>>> services = list(LocalServiceAdvertisement.discover('bpod'))Notes
Importing this class suppresses debug-level log messages from the
filelocklogger, as the per-file lock/unlock events it emits are too noisy for routine use. To re-enable them:logging.getLogger('filelock').setLevel(logging.DEBUG)- static discover(service_type, properties=None) ¶
Discover locally advertised services.
- Parameters:
- Yields:
LocalServiceInfo– Information structure describing the discovered services.- Return type: