microscope.device_server module

A class for serving microscope components.

This module provides a server to make microscope control objects available over Pyro. When called from the command line, this module will serve devices defined in a specified config file.

class microscope.device_server.DeviceServer(device_def, id_to_host: Mapping[str, str], id_to_port: Mapping[str, int], exit_event: Optional[multiprocessing.context.BaseContext.Event] = None)[source]

Bases: multiprocessing.context.Process


Create new instance with same settings.

This is useful to restart a device server.


Method to be run in sub-process; can be overridden in sub-class

class microscope.device_server.Filter[source]

Bases: logging.Filter


Pass, aggregate or suppress consecutive repetitions of a log message.

microscope.device_server.device(cls: Callable, host: str, port: int, conf: Mapping[str, Any] = {}, uid: Optional[str] = None)[source]

Define devices and where to serve them.

A device definition for use in deviceserver config files.

  • clsDevice class of device to serve or function that returns a map of Device instances to wanted Pyro ID. The device class will be constructed, or the function will be called, with the arguments in conf.

  • host – hostname or ip address serving the devices.

  • port – port number used to serve the devices.

  • conf – keyword arguments for cls. The device or function are effectively constructed or called with cls(**conf).

  • uid – used to identify “floating” devices (see documentation for FloatingDeviceMixin). This must be specified if cls is a floating device.


def construct_devices() -> typing.Dict[str, Device]:
    camera = Camera(some, arguments)
    # ... any other configuration that might be wanted
    return {'RedCamera': camera}

    # passing a function that returns devices
    device(construct_devices, '', 8000),
    # passing a Device class
    device(Camera, '', 8001,
           conf={'kwarg1': some, 'kwarg2': arguments})
microscope.device_server.serve_devices(devices, exit_event=None)[source]