• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

4 of 5 new or added lines in 3 files covered. (80.0%)

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

55.88
/src/python/pants/pantsd/pants_daemon_client.py
1
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
1✔
5

6
import logging
1✔
7
import os
1✔
8
from dataclasses import dataclass
1✔
9

10
from pants.engine.internals.native_engine import py_bin_name
1✔
11
from pants.option.options import Options
1✔
12
from pants.pantsd import pants_daemon
1✔
13
from pants.pantsd.process_manager import PantsDaemonProcessManager
1✔
14

15
logger = logging.getLogger(__name__)
1✔
16

17

18
class PantsDaemonClient(PantsDaemonProcessManager):
1✔
19
    """A client for interacting with a "potentially running" pantsd instance."""
20

21
    @dataclass(frozen=True)
1✔
22
    class Handle:
1✔
23
        """A handle to a "probably running" pantsd instance.
24

25
        We attempt to verify that the pantsd instance is still running when we create a Handle, but
26
        after it has been created it is entirely possible that the pantsd instance perishes.
27
        """
28

29
        pid: int
1✔
30
        port: int
1✔
31
        metadata_base_dir: str
1✔
32

33
    def __init__(self, bootstrap_options: Options):
1✔
UNCOV
34
        super().__init__(bootstrap_options, daemon_entrypoint=pants_daemon.__name__)
×
35

36
    def maybe_launch(self) -> PantsDaemonClient.Handle:
1✔
37
        """Creates and launches a daemon instance if one does not already exist."""
38
        with self.lifecycle_lock:
×
39
            if self.needs_restart(self.options_fingerprint):
×
40
                return self._launch()
×
41
            else:
42
                # We're already launched.
43
                return PantsDaemonClient.Handle(
×
44
                    pid=self.await_pid(10),
45
                    port=self.await_socket(10),
46
                    metadata_base_dir=self._metadata_base_dir,
47
                )
48

49
    def restart(self) -> PantsDaemonClient.Handle:
1✔
50
        """Restarts a running daemon instance."""
51
        with self.lifecycle_lock:
×
52
            # N.B. This will call `pantsd.terminate()` before starting.
53
            return self._launch()
×
54

55
    def _launch(self) -> PantsDaemonClient.Handle:
1✔
56
        """Launches pantsd in a subprocess.
57

58
        N.B. This should always be called under care of the `lifecycle_lock`.
59
        """
60
        # Propagate the bin name to pantsd.
61
        os.environ["__PANTS_BIN_NAME"] = py_bin_name()
×
62
        self.terminate()
×
63
        logger.debug("Launching pantsd")
×
64
        self.daemon_spawn()
×
65
        # Wait up to 60 seconds each for pantsd to write its pidfile and open its socket.
66
        pantsd_pid = self.await_pid(60)
×
67
        listening_port = self.await_socket(60)
×
68
        logger.debug(f"pantsd is running at pid {self.pid}, pailgun port is {listening_port}")
×
69
        return self.Handle(pantsd_pid, listening_port, self._metadata_base_dir)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc