Skip to content

Conversation

@ZeroIntensity
Copy link
Member

@ZeroIntensity ZeroIntensity commented Nov 20, 2025

@ZeroIntensity ZeroIntensity added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Nov 20, 2025
@bedevere-app bedevere-app bot added awaiting core review docs Documentation in the Doc dir skip news labels Nov 20, 2025
@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Nov 20, 2025
@ZeroIntensity
Copy link
Member Author

ZeroIntensity commented Nov 20, 2025

@colesbury, if you have time, I'd really appreciate your expertise here (especially on the PyThread_exit_thread warning).

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`.
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Contributor

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:

/* 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;
}

Copy link
Member Author

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.

ZeroIntensity and others added 2 commits November 21, 2025 08:42
Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants