Пример #1
0
  def _startModelRunnerSubprocess(cls, modelID):
    """
    :returns: the model runner subprocess wrapped in ManagedSubprocessTerminator
    """
    p = subprocess.Popen(
      args=[sys.executable,
            "-m", "htmengine.model_swapper.model_runner",
            "--modelID=" + str(modelID)],
      stdin=subprocess.PIPE, close_fds=True)

    _LOGGER.info("Started model_runner subprocess=%s for modelID=%s",
                 p.pid, modelID)
    return ManagedSubprocessTerminator(p)
Пример #2
0
    def _startModelSchedulerSubprocess(self):
        """
    Returns: the subprocess.Popen instance wrapped in
    ManagedSubprocessTerminator
    """
        # Override CWD for the metric collector subprocess so that it won't write
        # files in our source tree
        tempCWD = tempfile.mkdtemp(self.__class__.__name__ +
                                   '_startModelSchedulerSubprocess')
        self.addCleanup(shutil.rmtree, tempCWD)
        cwd = os.getcwd()
        os.chdir(tempCWD)

        stdout = open(os.path.join(tempCWD, "model_scheduler.stdout"), "a")
        stderr = open(os.path.join(tempCWD, "model_scheduler.stderr"), "a")

        try:
            p = subprocess.Popen(args=[
                sys.executable, "-m",
                "htmengine.model_swapper.model_scheduler_service"
            ],
                                 stdin=subprocess.PIPE,
                                 stdout=stdout,
                                 stderr=stderr)

            _LOGGER.info("Started model_scheduler subprocess=%s", p)

            # Give it a little time to get initialized; NOTE: if we don't wait, then
            # Python runtime doesn't get enough time to register its SIGINT handler
            # for KeyboardInterrupt, resulting in `-2` return code from the subprocess
            # instead of the 0 return code that we expect from normal termination
            _LOGGER.info("Waiting for model_scheduler subprocess to init")
            _waitForServiceReady(stderr.name)

            return ManagedSubprocessTerminator(p)
        finally:
            # Restore current working directory
            os.chdir(cwd)