Feature: Add hook point to handle custom time synchronization

From an email request:

I saw that flufl.lock expects distributed machines in an NFS environment to have synchronized clocks. But my project's users won’t be sysadmins and can’t easily adjust their clock times (if misaligned).

To account for this, I would like to determine each distributed process’s clock delta to a centralized time (e.g. NTP server or NFS system time) and incorporate this as an offset when resolving the flufl.lock timeouts.

The OP's suggestion was to add a time offset value to the Lock constructor and time calculations. This isn't an approach I want to take because I don't want to bake these kinds of settings in the public API, which would then require maintenance, testing, documentation, and backward compatibility guarantees.

My counter suggestion was to provide a non-public hook method, something like def _now(self) which would return datetime.now() by default, and then refactor all inline calls to the latter to use the former.

This would then allow the OP to subclass Lock, add the time offset as a parameter to the constructor, and override the base class _now() method. Something like the following:

def MyLock(Lock):
    def __init__(
        self,
        lockfile: str,
        lifetime: Interval | None = None,
        separator: str = SEP,
        default_timeout: Interval | None = None,
        time_offset: Interval | None = None,
    ):
        self._time_offset = time_offset
        super.__init__(lockfile, lifetime, separator, default_timeout)

    def _now(self):
        return datetime.now() + self._time_offset

This would be acceptable to me because from the project's PoV, it's just a refactoring and requires no test or doc changes.