Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-110850: Add PyTime_TimeRaw() function #118394

Merged
merged 3 commits into from
May 1, 2024
Merged

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Apr 29, 2024

Add "Raw" variant of PyTime functions:

  • PyTime_MonotonicRaw()
  • PyTime_PerfCounterRaw()
  • PyTime_TimeRaw()

Changes:

  • Add documentation and tests. Tests release the GIL while calling raw clock functions.
  • py_get_system_clock() and py_get_monotonic_clock() now check that the GIL is hold by the caller if raise_exc is non-zero.
  • Reimplement "Unchecked" functions with raw clock functions.

📚 Documentation preview 📚: https://cpython-previews--118394.org.readthedocs.build/

Add "Raw" variant of PyTime functions:

* PyTime_MonotonicRaw()
* PyTime_PerfCounterRaw()
* PyTime_TimeRaw()

Changes:

* Add documentation and tests. Tests release the GIL while calling
  raw clock functions.
* py_get_system_clock() and py_get_monotonic_clock() now check that
  the GIL is hold by the caller if raise_exc is non-zero.
* Reimplement "Unchecked" functions with raw clock functions.
@vstinner
Copy link
Member Author

cc @encukou

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
I have a few suggestions, which I've also tested locally. I've sent them as a PR: vstinner#2

Doc/c-api/time.rst Outdated Show resolved Hide resolved
Modules/_testcapi/time.c Show resolved Hide resolved
Python/pytime.c Show resolved Hide resolved
@vstinner
Copy link
Member Author

vstinner commented May 1, 2024

@encukou: I applied your suggestion, but I replaced the assert() with Py_FatalError(). Also, I added a code path with (void) (to ignore the result) to ignore a potential compiler warning about unused result variable.

@vstinner
Copy link
Member Author

vstinner commented May 1, 2024

Don't bother too much about "Unchecked" functions. Once this PR will land, I will write a PR to remove "Unchecked" functions (use "Raw" functions instead).

@encukou
Copy link
Member

encukou commented May 1, 2024

Thanks!
Looking forward to that :)

@vstinner vstinner enabled auto-merge (squash) May 1, 2024 17:04
@vstinner vstinner merged commit b52c753 into python:main May 1, 2024
38 checks passed
@vstinner vstinner deleted the time_raw branch May 1, 2024 18:05
SonicField pushed a commit to SonicField/cpython that referenced this pull request May 8, 2024
Add "Raw" variant of PyTime functions:

* PyTime_MonotonicRaw()
* PyTime_PerfCounterRaw()
* PyTime_TimeRaw()

Changes:

* Add documentation and tests. Tests release the GIL while calling
  raw clock functions.
* py_get_system_clock() and py_get_monotonic_clock() now check that
  the GIL is hold by the caller if raise_exc is non-zero.
* Reimplement "Unchecked" functions with raw clock functions.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants