Skip to content

Commit

Permalink
cli: If attribute CLOCK_BOOTTIME doesn't exist fall back
Browse files Browse the repository at this point in the history
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 jeffmahoney#10

Signed-off-by: Egbert Eich <eich@suse.com>
  • Loading branch information
e4t committed Sep 8, 2022
1 parent e96085e commit 38552ab
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion oauth2_clientd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 38552ab

Please sign in to comment.