• 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

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

4
import errno
1✔
5
import logging
1✔
6
import os
1✔
7
import sys
1✔
8

9
import psutil
1✔
10
from fasteners import InterProcessLock
1✔
11

12
from pants.util.dirutil import safe_delete
1✔
13

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

16

17
def print_to_stderr(message):
1✔
UNCOV
18
    print(message, file=sys.stderr)
×
19

20

21
class OwnerPrintingInterProcessFileLock(InterProcessLock):
1✔
22
    @property
1✔
23
    def message_path(self):
1✔
UNCOV
24
        return f"{self.path_str}.lock_message"
×
25

26
    @property
1✔
27
    def path_str(self):
1✔
UNCOV
28
        return self.path.decode()
×
29

30
    @property
1✔
31
    def missing_message_output(self):
1✔
UNCOV
32
        return f"Pid {os.getpid()} waiting for a file lock ({self.path_str}), but there was no message at {self.message_path} indicating who is holding it."
×
33

34
    def acquire(self, message_fn=print_to_stderr, **kwargs):
1✔
UNCOV
35
        logger.debug(f"acquiring lock: {self!r}")
×
UNCOV
36
        super().acquire(blocking=False)
×
UNCOV
37
        if not self.acquired:
×
UNCOV
38
            try:
×
UNCOV
39
                with open(self.message_path, "rb") as f:
×
UNCOV
40
                    message = f.read().decode("utf-8", "replace")
×
UNCOV
41
                    output = f"PID {os.getpid()} waiting for a file lock ({self.path_str}) held by: {message}"
×
UNCOV
42
            except OSError as e:
×
UNCOV
43
                if e.errno == errno.ENOENT:
×
UNCOV
44
                    output = self.missing_message_output
×
45
                else:
46
                    raise
×
UNCOV
47
            message_fn(output)
×
UNCOV
48
            super().acquire(**kwargs)
×
49

UNCOV
50
        if self.acquired:
×
UNCOV
51
            current_process = psutil.Process()
×
UNCOV
52
            cmd_line = " ".join(current_process.cmdline())
×
UNCOV
53
            message = f"{current_process.pid} ({cmd_line})"
×
UNCOV
54
            with open(self.message_path, "wb") as f:
×
UNCOV
55
                f.write(message.encode())
×
56

UNCOV
57
        return self.acquired
×
58

59
    def release(self):
1✔
UNCOV
60
        logger.debug(f"releasing lock: {self!r}")
×
UNCOV
61
        if self.acquired:
×
UNCOV
62
            safe_delete(self.message_path)
×
UNCOV
63
        return super().release()
×
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