def worker_killer_task(config, master_address, worker_address): from scannerpy import ProtobufGenerator, Config, start_worker import time import grpc import subprocess import signal import os 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 protobufs = ProtobufGenerator(config) # Kill worker channel = grpc.insecure_channel( worker_address, options=[('grpc.max_message_length', 24499183 * 2)]) worker = protobufs.WorkerStub(channel) try: worker.Shutdown(protobufs.Empty()) except grpc.RpcError as e: status = e.code() if status == grpc.StatusCode.UNAVAILABLE: print('could not shutdown worker!') exit(1) else: raise ScannerException('Worker errored with status: {}' .format(status)) # Spawn a worker that we will force kill script_dir = os.path.dirname(os.path.realpath(__file__)) with open(os.devnull, 'w') as fp: p = subprocess.Popen( ['python ' + script_dir + '/spawn_worker.py'], shell=True, stdout=fp, stderr=fp, preexec_fn=os.setsid) # Wait a bit for the worker to do its thing time.sleep(10) # Force kill worker process to trigger fault tolerance os.killpg(os.getpgid(p.pid), signal.SIGTERM) p.communicate() # Wait for fault tolerance to kick in time.sleep(25) # Spawn the worker again subprocess.call(['python ' + script_dir + '/spawn_worker.py'], shell=True)
def worker_shutdown_task(config, master_address, worker_address): from scannerpy import ProtobufGenerator, Config, start_worker import time import grpc import subprocess 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 protobufs = ProtobufGenerator(config) # Wait to kill worker time.sleep(8) # Kill worker channel = grpc.insecure_channel( worker_address, options=[('grpc.max_message_length', 24499183 * 2)]) worker = protobufs.WorkerStub(channel) try: worker.Shutdown(protobufs.Empty()) except grpc.RpcError as e: status = e.code() if status == grpc.StatusCode.UNAVAILABLE: print('could not shutdown worker!') exit(1) else: raise ScannerException('Worker errored with status: {}' .format(status)) # Wait a bit time.sleep(15) script_dir = os.path.dirname(os.path.realpath(__file__)) subprocess.call(['python ' + script_dir + '/spawn_worker.py'], shell=True)
def worker_killer_task(config, master_address): from scannerpy import ProtobufGenerator, Config, start_worker import time import grpc import subprocess import signal import os 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 scannerpy.libscanner as bindings protobufs = ProtobufGenerator(config) # Spawn a worker that we will force kill script_dir = os.path.dirname(os.path.realpath(__file__)) with open(os.devnull, 'w') as fp: p = subprocess.Popen( [ 'python ' + script_dir + '/spawn_worker.py {:d}'.format(force_kill_spawn_port) ], shell=True, stdout=fp, stderr=fp, preexec_fn=os.setsid) # Wait a bit for the worker to do its thing time.sleep(10) # Force kill worker process to trigger fault tolerance os.killpg(os.getpgid(p.pid), signal.SIGTERM) p.kill() p.communicate() # Wait for fault tolerance to kick in time.sleep(15) # Spawn the worker again subprocess.call( [ 'python ' + script_dir + '/spawn_worker.py {:d}'.format(normal_spawn_port) ], shell=True)
from django.core.management.base import BaseCommand from query.models import Video, Face, LabelSet, Frame from scannerpy import ProtobufGenerator, Config import os import cv2 import math import numpy as np import tensorflow as tf import align.detect_face from collections import defaultdict from array import * from functools import wraps import inspect cfg = Config() proto = ProtobufGenerator(cfg) def initializer(func): """ Automatically assigns the parameters. >>> class process: ... @initializer ... def __init__(self, cmd, reachable=False, user='******'): ... pass >>> p = process('halt', True) >>> p.cmd, p.reachable, p.user ('halt', True, 'root') """ names, varargs, keywords, defaults = inspect.getargspec(func)
from scannerpy import ProtobufGenerator, Config, start_worker import time import grpc import sys 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 scannerpy.libscanner as bindings con = Config(config_path='/tmp/config_test') protobufs = ProtobufGenerator(con) master_address = str(con.master_address) + ':' + str(con.master_port) port = int(sys.argv[1]) 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=port, watchdog=False)