Skip to content

Conversation

@cxzhong
Copy link
Contributor

@cxzhong cxzhong commented Dec 5, 2025

Fix #40980 (comment) , add a tolerance in this function.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

Updated doctest output to clarify expected behavior of interruptible_sleep function.
@cxzhong cxzhong requested a review from vbraun December 5, 2025 13:47
@cxzhong cxzhong changed the title add doctests tolerance add a doctests tolerance Dec 5, 2025
Updated doctest to reflect changes in RuntimeError messages and added output for 'data'.
Updated doctest to remove absolute tolerance in interruptible_sleep.
@cxzhong
Copy link
Contributor Author

cxzhong commented Dec 6, 2025

But I still do not understand why we have

**********************************************************************
File "src/sage/doctest/util.py", line 846, in sage.doctest.util.inaccuracy_tolerance
Failed example:
    with ensure_interruptible_after(2) as data: interruptible_sleep(1r)
Expected:
    Traceback (most recent call last):
    ...
    RuntimeError: Function terminates early after 1.00... < 2.0000 seconds
Got:
    <BLANKLINE>
    Traceback (most recent call last):
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/forker.py", line 734, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/forker.py", line 1158, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.doctest.util.inaccuracy_tolerance[9]>", line 1, in <module>
        with ensure_interruptible_after(Integer(2)) as data: interruptible_sleep(1)
      File "/Users/buildbot-sage/worker/sage_git/build/local/var/lib/sage/venv-python3.12.5/lib/python3.12/contextlib.py", line 144, in __exit__
        next(self.gen)
      File "/Users/buildbot-sage/worker/sage_git/build/src/sage/doctest/util.py", line 904, in ensure_interruptible_after
        raise RuntimeError(f"Function terminates early after {elapsed:.4f} < {seconds:.4f} seconds")
    RuntimeError: Function terminates early after 0.9982 < 2.0000 seconds
**********************************************************************

I am confuesd it is less than 1.

@cxzhong cxzhong requested review from dimpase and tobiasdiez December 6, 2025 06:52
@vbraun
Copy link
Member

vbraun commented Dec 6, 2025

That appears to be a headscratcher, indeed

My best guess is that there was a ntp time update during the run, which will skew clock_gettime(CLOCK_REALTIME, ...) but not alarm.

We should probably use clock_gettime(CLOCK_MONOTONIC, ...) for measuring time differences, this is (like sleep and alarm) independent of any changes to the clock by ntp or user actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants