def METHOD_NAME(
    self, stderr_fileno: int, cancellation_latch: PySessionCancellationLatch, timeout: float
):
    """Acquires exclusive access within the daemon.
    Periodically prints a message on the given stderr_fileno while exclusive access cannot be
    acquired.
    TODO: This method will be removed as part of #7654, so it currently polls the lock and
    cancellation latch rather than waiting for both of them asynchronously, which would be a bit
    cleaner.
    """
    render_timeout = 5
    should_poll_forever = timeout <= 0
    start = time.time()
    render_deadline = start + render_timeout
    deadline = None if should_poll_forever else start + timeout
    def should_keep_polling(now):
        return not cancellation_latch.is_cancelled() and (not deadline or deadline > now)
    acquired = self._run_lock.acquire(blocking=False)
    if not acquired:
        # If we don't acquire immediately, send an explanation.
        length = "forever" if should_poll_forever else f"up to {timeout} seconds"
        self._send_stderr(
            stderr_fileno,
            f"Another pants invocation is running. Will wait {length} for it to finish before giving up.\n"
            "If you don't want to wait for the first run to finish, please press Ctrl-C and run "
            "this command with PANTS_CONCURRENT=True in the environment.\n",
        )
    while True:
        now = time.time()
        if acquired:
            try:
                yield
                break
            finally:
                self._run_lock.release()
        elif should_keep_polling(now):
            if now > render_deadline:
                self._send_stderr(
                    stderr_fileno,
                    f"Waiting for invocation to finish (waited for {int(now - start)}s so far)...\n",
                )
                render_deadline = now + render_timeout
            acquired = self._run_lock.acquire(blocking=True, timeout=0.1)
        else:
            raise ExclusiveRequestTimeout(
                "Timed out while waiting for another pants invocation to finish."
            )