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.

This module can be called as a program to serve devices over Pyro, like so:

python -m microscope.device_server CONFIG-FILEPATH

where CONFIG-FILEPATH is the path for a python file that defines a DEVICES = [device(...), ...]

class microscope.device_server.DeviceServer(device_def, options: microscope.device_server.DeviceServerOptions, 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

Initialise a device and serve at host/port according to its id.

Parameters
  • device_def – definition of the device.

  • options – configuration for the device server.

  • id_to_host – host or mapping of device identifiers to hostname.

  • id_to_port – map or mapping of device identifiers to port number.

  • exit_event – a shared event to signal that the process should quit.

clone()[source]

Create new instance with same settings.

This is useful to restart a device server.

run()[source]

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

class microscope.device_server.DeviceServerOptions(config_fpath: str, logging_level: int)[source]

Bases: object

Class to define configuration for a device server.

The different fields map to the different device-server command line options.

config_fpath: str
logging_level: int
class microscope.device_server.Filter[source]

Bases: logging.Filter

filter(record)[source]

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.

Parameters
  • 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.

Example

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

DEVICES = [
    # passing a function that returns devices
    device(construct_devices, '127.0.0.1', 8000),
    # passing a Device class
    device(Camera, '127.0.0.1', 8001,
           conf={'kwarg1': some, 'kwarg2': arguments})
]
microscope.device_server.main(argv: Sequence[str])int[source]
microscope.device_server.serve_devices(devices, options: microscope.device_server.DeviceServerOptions, exit_event=None)[source]
microscope.device_server.validate_devices(configfile)[source]