LocalServiceAdvertisement

class bpod_core.ipc.LocalServiceAdvertisement

Bases: AbstractContextManager

File-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 filelock logger, 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:
  • service_type (str) – The service type to discover.

  • properties (dict, optional) – Properties to match against the service’s properties.

Yields:

LocalServiceInfo – Information structure describing the discovered services.

Return type:

Iterator[LocalServiceInfo]

close()

Remove the service advertisement and clean up empty directories.

Return type:

None

service_file: Path

Path to the advertisement file.