Skip to content

gh-110850: Add PyTime_TimeRaw() function#118394

Merged
vstinner merged 3 commits into
python:mainfrom
vstinner:time_raw
May 1, 2024
Merged

gh-110850: Add PyTime_TimeRaw() function#118394
vstinner merged 3 commits into
python:mainfrom
vstinner:time_raw

Conversation

@vstinner

@vstinner vstinner commented Apr 29, 2024

Copy link
Copy Markdown
Member

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
Copy Markdown
Member Author

cc @encukou

@encukou encukou left a comment

Copy link
Copy Markdown
Member

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

Comment thread Doc/c-api/time.rst Outdated
Comment thread Modules/_testcapi/time.c
Comment thread Python/pytime.c
@vstinner

vstinner commented May 1, 2024

Copy link
Copy Markdown
Member Author

@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

vstinner commented May 1, 2024

Copy link
Copy Markdown
Member Author

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

encukou commented May 1, 2024

Copy link
Copy Markdown
Member

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
@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