From 43df77adc9e444d8eecda55d199c312b7f58e77d Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Mon, 19 Jan 2026 04:28:28 -0500 Subject: [PATCH] time.monotonic() is always available --- av/container/core.pxd | 1 - av/container/core.pyi | 2 -- av/container/core.pyx | 12 +++--------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/av/container/core.pxd b/av/container/core.pxd index 87bb792b3..71d18ae91 100644 --- a/av/container/core.pxd +++ b/av/container/core.pxd @@ -14,7 +14,6 @@ ctypedef struct timeout_info: cdef class Container: - cdef readonly bint writeable cdef lib.AVFormatContext *ptr diff --git a/av/container/core.pyi b/av/container/core.pyi index 26e76ed2c..2ca547028 100644 --- a/av/container/core.pyi +++ b/av/container/core.pyi @@ -100,8 +100,6 @@ class Container: exc_val: BaseException | None, exc_tb: TracebackType | None, ) -> None: ... - def set_timeout(self, timeout: Real | None) -> None: ... - def start_timeout(self) -> None: ... def chapters(self) -> list[Chapter]: ... def set_chapters(self, chapters: list[Chapter]) -> None: ... diff --git a/av/container/core.pyx b/av/container/core.pyx index 299ac6ed3..53c873372 100755 --- a/av/container/core.pyx +++ b/av/container/core.pyx @@ -28,20 +28,14 @@ from av.logging import Capture as LogCapture cdef object _cinit_sentinel = object() - -# We want to use the monotonic clock if it is available. -cdef object clock = getattr(time, "monotonic", time.time) - -cdef int interrupt_cb (void *p) noexcept nogil: +cdef int interrupt_cb(void *p) noexcept nogil: cdef timeout_info info = dereference( p) if info.timeout < 0: # timeout < 0 means no timeout return 0 cdef double current_time with gil: - current_time = clock() - - # Check if the clock has been changed. + current_time = time.monotonic() if current_time < info.start_time: # Raise this when we get back to Python. stash_exception((RuntimeError, RuntimeError("Clock has been changed to before timeout start"), None)) @@ -330,7 +324,7 @@ cdef class Container: self.interrupt_callback_info.timeout = timeout cdef start_timeout(self): - self.interrupt_callback_info.start_time = clock() + self.interrupt_callback_info.start_time = time.monotonic() cdef _assert_open(self): if self.ptr == NULL: