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

pantsbuild / pants / 18252174847

05 Oct 2025 01:36AM UTC coverage: 43.382% (-36.9%) from 80.261%
18252174847

push

github

web-flow
run tests on mac arm (#22717)

Just doing the minimal to pull forward the x86_64 pattern.

ref #20993

25776 of 59416 relevant lines covered (43.38%)

1.3 hits per line

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

73.91
/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
3✔
5
import logging
3✔
6
import os
3✔
7
import sys
3✔
8

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

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

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

16

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

20

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

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

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

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

57
        return self.acquired
3✔
58

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