def start_worker(master_address, machine_params=None, port=None, config=None, config_path=None, block=False, watchdog=True): """ Start a worker instance on this node. Args: master_address: The address of the master server to connect this worker to. Kwargs: config: A scanner Config object. If specified, config_path is ignored. config_path: Path to a Scanner configuration TOML, by default assumed to be `~/.scanner.toml`. block: If true, will wait until the server is shutdown. Server will not shutdown currently unless wait_ror_server_shutdown is eventually called. Returns: A cpp database instance. """ config = config or Config(config_path) port = port or config.worker_port # Load all protobuf types import libscanner as bindings db = bindings.Database( config.storage_config, #storage_config, config.db_path, master_address) machine_params = machine_params or bindings.default_machine_params() result = bindings.start_worker(db, machine_params, str(port).encode('ascii'), watchdog) if not result.success: raise ScannerException('Failed to start worker: {}'.format(result.msg)) if block: bindings.wait_for_server_shutdown(db) return result
from scannerpy import ProtobufGenerator, Config, start_worker import time import grpc c = Config(None) import scanner.metadata_pb2 as metadata_types import scanner.engine.rpc_pb2 as rpc_types import scanner.types_pb2 as misc_types import libscanner as bindings con = Config(config_path='/tmp/config_test') protobufs = ProtobufGenerator(con) master_address = 'localhost:5005' params = bindings.default_machine_params() mp = protobufs.MachineParameters() mp.ParseFromString(params) del mp.gpu_ids[:] params = mp.SerializeToString() start_worker(master_address, machine_params=params, config=con, block=True, port=5010, watchdog=False)