-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
gh-141004: Document missing PyThread* APIs
#141810
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
base: main
Are you sure you want to change the base?
Conversation
|
@colesbury, if you have time, I'd really appreciate your expertise here (especially on the |
Doc/c-api/init.rst
Outdated
| been released. | ||
| If *intr_flag* is ``1``, acquiring the lock may be interrupted by CTRL^C, | ||
| in which case this function returns :c:enumerator:`PY_LOCK_INTR`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be any signal but the signal handler should raise an exception. Well, CTRL+C is any example which raises KeyboardInterrupt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the caller just needs to call PyErr_CheckSignals as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyThread_acquire_lock_timed doesn't set an exception. If PyThread_acquire_lock_timed returns PY_LOCK_INTR, the caller typically checks for ctrl-c (and other signals) with Py_MakePendingCalls(). The typical pattern is:
cpython/Modules/_threadmodule.c
Lines 98 to 112 in 9524203
| /* first a simple non-blocking try without releasing the GIL */ | |
| r = PyThread_acquire_lock_timed(lock, 0, 0); | |
| if (r == PY_LOCK_FAILURE && microseconds != 0) { | |
| Py_BEGIN_ALLOW_THREADS | |
| r = PyThread_acquire_lock_timed(lock, microseconds, 1); | |
| Py_END_ALLOW_THREADS | |
| } | |
| if (r == PY_LOCK_INTR) { | |
| /* Run signal handlers if we were interrupted. Propagate | |
| * exceptions from signal handlers, such as KeyboardInterrupt, by | |
| * passing up PY_LOCK_INTR. */ | |
| if (Py_MakePendingCalls() < 0) { | |
| return PY_LOCK_INTR; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note about Py_MakePendingCalls, let me know what either of you think about the wording.
Co-authored-by: Victor Stinner <vstinner@python.org>
📚 Documentation preview 📚: https://cpython-previews--141810.org.readthedocs.build/en/141810/c-api/init.html#legacy-locking-apis