コード例 #1
0
def launch_waiter(
        *,
        workdir: str,
        config: Mapping | None = None,
        cleanup_wait_time: int = 0) -> tuple[PantsJoinHandle, int, int, str]:
    """Launch a process that will wait forever for a file to be created.

    Returns the pants client handle, the pid of the waiting process, the pid of a child of the
    waiting process, and the file to create to cause the waiting child to exit.
    """
    file_to_make = os.path.join(workdir, "some_magic_file")
    waiter_pid_file = os.path.join(workdir, "pid_file")
    child_pid_file = os.path.join(workdir, "child_pid_file")

    argv = [
        "run",
        "testprojects/src/python/coordinated_runs:waiter",
        "--",
        file_to_make,
        waiter_pid_file,
        child_pid_file,
        str(cleanup_wait_time),
    ]
    client_handle = run_pants_with_workdir_without_waiting(argv,
                                                           workdir=workdir,
                                                           config=config)
    waiter_pid = -1
    for _ in attempts("The waiter process should have written its pid."):
        waiter_pid_str = maybe_read_file(waiter_pid_file)
        child_pid_str = maybe_read_file(child_pid_file)
        if waiter_pid_str and child_pid_str:
            waiter_pid = int(waiter_pid_str)
            child_pid = int(child_pid_str)
            break
    return client_handle, waiter_pid, child_pid, file_to_make
コード例 #2
0
    def _launch_waiter(cls, workdir: str, config) -> Tuple[PantsJoinHandle, int, str]:
        """Launch a process via pantsd that will wait forever for the a file to be created.

        Returns the pid of the pantsd client, the pid of the waiting child process, and the file to
        create to cause the waiting child to exit.
        """
        file_to_make = os.path.join(workdir, "some_magic_file")
        waiter_pid_file = os.path.join(workdir, "pid_file")

        argv = [
            "run",
            "testprojects/src/python/coordinated_runs:waiter",
            "--",
            file_to_make,
            waiter_pid_file,
        ]
        client_handle = cls.run_pants_with_workdir_without_waiting(
            argv, workdir=workdir, config=config
        )
        waiter_pid = -1
        for _ in attempts("The waiter process should have written its pid."):
            waiter_pid_str = maybe_read_file(waiter_pid_file)
            if waiter_pid_str:
                waiter_pid = int(waiter_pid_str)
                break
        return client_handle, waiter_pid, file_to_make
コード例 #3
0
def load_digest(output_dir):
  read_file = maybe_read_file('{}.digest'.format(output_dir), binary_mode=False)
  if read_file:
    fingerprint, length = read_file.split(':')
    return Digest(fingerprint, int(length))
  else:
    return None
コード例 #4
0
    def _extract_remote_exception(self, pantsd_pid, nailgun_error):
        """Given a NailgunError, returns a Terminated exception with additional info (where
        possible).

        This method will include the entire exception log for either the `pid` in the NailgunError,
        or failing that, the `pid` of the pantsd instance.
        """
        sources = [pantsd_pid]
        if nailgun_error.pid is not None:
            sources = [abs(nailgun_error.pid)] + sources

        exception_text = None
        for source in sources:
            log_path = ExceptionSink.exceptions_log_path(for_pid=source)
            exception_text = maybe_read_file(log_path)
            if exception_text:
                break

        exception_suffix = (
            "\nRemote exception:\n{}".format(exception_text) if exception_text else ""
        )
        return self.Terminated(
            "abruptly lost active connection to pantsd runner: {!r}{}".format(
                nailgun_error, exception_suffix
            )
        )
コード例 #5
0
  def load(cls, digested_path):
    """Load a Digest from a `.digest` file adjacent to the given digested_path.

    :return: A Digest, or None if the Digest did not exist.
    """
    read_file = maybe_read_file(cls._path(digested_path))
    if read_file:
      fingerprint, length = read_file.split(':')
      return Digest(fingerprint, int(length))
    else:
      return None
コード例 #6
0
ファイル: fs.py プロジェクト: jsirois/pants
  def load(cls, directory):
    """Load a Digest from a `.digest` file adjacent to the given directory.

    :return: A Digest, or None if the Digest did not exist.
    """
    read_file = maybe_read_file(cls._path(directory))
    if read_file:
      fingerprint, length = read_file.split(':')
      return Digest(fingerprint, int(length))
    else:
      return None
コード例 #7
0
def test_workunits_logger() -> None:
    with setup_tmpdir({}) as tmpdir:
        dest = os.path.join(tmpdir, "dest.log")
        pants_run = run_pants([
            "--backend-packages=+['workunit_logger','pants.backend.python']",
            f"--workunit-logger-dest={dest}",
            "list",
            "3rdparty::",
        ])
        pants_run.assert_success()
        # Assert that the file was created and non-empty.
        assert maybe_read_file(dest)
def test_ctrl_c() -> None:
    with temporary_workdir() as workdir:
        dest = os.path.join(workdir, "dest.log")

        # Start a pantsd run that will wait forever, then kill the pantsd client.
        client_handle, _, _ = launch_waiter(workdir=workdir, config=workunit_logger_config(dest))
        client_pid = client_handle.process.pid
        os.kill(client_pid, signal.SIGINT)

        # Confirm that finish is still called (even though it may be backgrounded in the server).
        for _ in attempts("The log should eventually show that the SWH shut down."):
            content = maybe_read_file(dest)
            if content and FINISHED_SUCCESSFULLY in content:
                break
コード例 #9
0
def run(args: list[str],
        success: bool = True,
        *,
        files: dict[str, str] | None = None) -> tuple[PantsResult, str | None]:
    with setup_tmpdir(files or {}) as tmpdir:
        dest = os.path.join(tmpdir, "dest.log")
        normalized_args = [arg.format(tmpdir=tmpdir) for arg in args]
        pants_run = run_pants(normalized_args,
                              config=workunit_logger_config(dest))
        if success:
            pants_run.assert_success()
            confirm_eventual_success(dest)
        else:
            pants_run.assert_failure()
        return pants_run, maybe_read_file(dest)
コード例 #10
0
def confirm_eventual_success(log_dest: str) -> None:
    for _ in attempts(
            "The log should eventually show that the SWH shut down."):
        content = maybe_read_file(log_dest)
        if content and FINISHED_SUCCESSFULLY in content:
            break