Remove monotonic_time_coarse datetime helper (#104892)

This commit is contained in:
J. Nick Koston 2023-12-03 22:10:13 -10:00 committed by GitHub
parent 3b5e498c30
commit 67039e0f26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 35 deletions

View File

@ -5,9 +5,7 @@ import bisect
from contextlib import suppress from contextlib import suppress
import datetime as dt import datetime as dt
from functools import partial from functools import partial
import platform
import re import re
import time
from typing import Any from typing import Any
import zoneinfo import zoneinfo
@ -16,7 +14,6 @@ import ciso8601
DATE_STR_FORMAT = "%Y-%m-%d" DATE_STR_FORMAT = "%Y-%m-%d"
UTC = dt.UTC UTC = dt.UTC
DEFAULT_TIME_ZONE: dt.tzinfo = dt.UTC DEFAULT_TIME_ZONE: dt.tzinfo = dt.UTC
CLOCK_MONOTONIC_COARSE = 6
# EPOCHORDINAL is not exposed as a constant # EPOCHORDINAL is not exposed as a constant
# https://github.com/python/cpython/blob/3.10/Lib/zoneinfo/_zoneinfo.py#L12 # https://github.com/python/cpython/blob/3.10/Lib/zoneinfo/_zoneinfo.py#L12
@ -476,29 +473,3 @@ def _datetime_ambiguous(dattim: dt.datetime) -> bool:
assert dattim.tzinfo is not None assert dattim.tzinfo is not None
opposite_fold = dattim.replace(fold=not dattim.fold) opposite_fold = dattim.replace(fold=not dattim.fold)
return _datetime_exists(dattim) and dattim.utcoffset() != opposite_fold.utcoffset() return _datetime_exists(dattim) and dattim.utcoffset() != opposite_fold.utcoffset()
def __gen_monotonic_time_coarse() -> partial[float]:
"""Return a function that provides monotonic time in seconds.
This is the coarse version of time_monotonic, which is faster but less accurate.
Since many arm64 and 32-bit platforms don't support VDSO with time.monotonic
because of errata, we can't rely on the kernel to provide a fast
monotonic time.
https://lore.kernel.org/lkml/20170404171826.25030-1-marc.zyngier@arm.com/
"""
# We use a partial here since its implementation is in native code
# which allows us to avoid the overhead of the global lookup
# of CLOCK_MONOTONIC_COARSE.
return partial(time.clock_gettime, CLOCK_MONOTONIC_COARSE)
monotonic_time_coarse = time.monotonic
with suppress(Exception):
if (
platform.system() == "Linux"
and abs(time.monotonic() - __gen_monotonic_time_coarse()()) < 1
):
monotonic_time_coarse = __gen_monotonic_time_coarse()

View File

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
from datetime import UTC, datetime, timedelta from datetime import UTC, datetime, timedelta
import time
import pytest import pytest
@ -737,8 +736,3 @@ def test_find_next_time_expression_tenth_second_pattern_does_not_drift_entering_
assert (next_target - prev_target).total_seconds() == 60 assert (next_target - prev_target).total_seconds() == 60
assert next_target.second == 10 assert next_target.second == 10
prev_target = next_target prev_target = next_target
def test_monotonic_time_coarse() -> None:
"""Test monotonic time coarse."""
assert abs(time.monotonic() - dt_util.monotonic_time_coarse()) < 1