Skip to content

Commit f0d0b10

Browse files
authored
Use time.monotonic() instead of time.clock_gettime()
This makes this compatible with Windows and macOS, where time.clock_gettime() does not exist.
1 parent 4f729ce commit f0d0b10

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

demos/tinytv-stream.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,13 +736,15 @@ def show_stats(byte_counts: Iterable[int]) -> None:
736736
737737
:param byte_counts: Iterable of byte counts per frame.
738738
"""
739-
start_time = time.clock_gettime(time.CLOCK_MONOTONIC)
739+
# If we needed high-precision, such as for benchmarking very short times, we might want to use time.perf_counter().
740+
# However, time.monotonic() is sufficient for simple stats reporting.
741+
start_time = time.monotonic()
740742
time_deque: deque[float] = deque(maxlen=100)
741743
byte_count_deque: deque[int] = deque(maxlen=100)
742744
next_display_update = 0.0
743745
last_status_len = 0
744746
for frame_count, byte_count in enumerate(byte_counts):
745-
now = time.clock_gettime(time.CLOCK_MONOTONIC)
747+
now = time.monotonic()
746748
time_deque.append(now)
747749
byte_count_deque.append(byte_count)
748750
if now >= next_display_update and len(time_deque) > 1:

0 commit comments

Comments
 (0)