From 38552abe07400bf78e54b3584dfdfa064147348d Mon Sep 17 00:00:00 2001 From: Egbert Eich Date: Thu, 8 Sep 2022 08:12:26 +0200 Subject: [PATCH] cli: If attribute CLOCK_BOOTTIME doesn't exist fall back time.CLOCK_BOOTTIME has only been introduced to the `time` module with Python 3.7. To support older versions, provide a fallback to time.CLOCK_MONOTONIC. Fixes #10 Signed-off-by: Egbert Eich --- oauth2_clientd/cli.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/oauth2_clientd/cli.py b/oauth2_clientd/cli.py index f6a0c9e..2f270ef 100755 --- a/oauth2_clientd/cli.py +++ b/oauth2_clientd/cli.py @@ -68,7 +68,11 @@ def token_needs_refreshing(token: Dict[str, Any], threshold: int) -> bool: return token['expires_at'] + threshold > time.time() def get_boottime() -> int: - return int(time.clock_gettime(time.CLOCK_BOOTTIME)) + try: + val = int(time.clock_gettime(time.CLOCK_BOOTTIME)) + except AttributeError: + val = int(time.clock_gettime(time.CLOCK_MONOTONIC)) + return val # This is a workaround. All implementations of sleep() in Python use # CLOCK_MONOTONIC, which has the advantage of never going backward but it