Ejemplo n.º 1
0
    def launch(self):
        """
        启动器主函数
        """
        self._set_affinity()
        Communicator()
        Logger().init_module_logger()
        ForkProxy()
        Logger().info("Launcher init success!")

        preprocessor_proc = modules.Process(modules.Preprocessor)
        preprocessor_proc.start()
        self.preprocessor_pid = preprocessor_proc.pid
        Logger().info("Preprocessor fork success!")

        monitor_proc = modules.Process(modules.Monitor)
        monitor_proc.start()
        self.monitor_pid = monitor_proc.pid
        Logger().info("Monitor fork success!")

        signal.signal(signal.SIGCHLD, self._wait_child)
        try:
            ForkProxy().listen()
        except KeyboardInterrupt:
            self.exit = True
Ejemplo n.º 2
0
def monitor_fixture():
    from core.components.runtime_info import RuntimeInfo
    RuntimeInfo._refresh_system_info = types.MethodType(
        _refresh_info_hook, RuntimeInfo)

    helper.reset_db()
    Communicator()
    Logger()
    ForkProxy()
    module_proc = modules.Process(modules.Monitor)
    module_proc.start()

    fork_proxy_proc = multiprocessing.Process(target=_fork_proxy)
    fork_proxy_proc.start()

    yield {"set_system_info": _set_system_info}

    root_proc = psutil.Process(module_proc.pid)
    fork_proc = psutil.Process(fork_proxy_proc.pid)
    procs = root_proc.children(recursive=True)
    procs.append(fork_proc)
    procs.append(root_proc)
    try:
        for p in procs:
            p.terminate()
            p.wait(2)
    except Exception:
        raise Exception("Module process may not be killed success!")

    module_proc.join(3)
    fork_proxy_proc.join(3)

    helper.reset_db()
    Communicator.reset()
Ejemplo n.º 3
0
 def listen(self):
     """
     监听创建模块进程队列,创建进程并返回pid
     """
     while True:
         process_kwargs = self.request_queue.get(True)
         try:
             proc = modules.Process(**process_kwargs)
             proc.start()
             pid = proc.pid
         except Exception as e:
             Logger().error("Fork proxy error when start new module!",
                            exc_info=e)
             result = {"pid": 0}
         else:
             Logger().info("Fork module {} success with pid {}!".format(
                 process_kwargs["module_cls"].__name__, pid))
             result = {"pid": pid}
         self.result_queue.put(result)
Ejemplo n.º 4
0
def preprocessor_fixture():
    helper.reset_db()
    Communicator()
    Logger()
    module_proc = modules.Process(modules.Preprocessor)
    module_proc.start()

    yield module_proc

    root_proc = psutil.Process(module_proc.pid)
    procs = root_proc.children(recursive=True)
    try:
        root_proc.terminate()
        root_proc.wait(10)
        module_proc.join(5)
        for p in procs:
            p.terminate()
            p.wait(10)
    except psutil.TimeoutExpired:
        raise Exception("Module process may not be killed success!")

    helper.reset_db()
    Communicator.reset()