This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add (optional) threadstate to: PyOS_InterruptOccurred()
Type: enhancement Stage:
Components: C API Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: seberg, vstinner
Priority: normal Keywords:

Created on 2020-06-19 14:11 by seberg, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg371885 - (view) Author: Sebastian Berg (seberg) * Date: 2020-06-19 14:11
In https://bugs.python.org/issue40826 it was defined that `PyOS_InterruptOccurred()` can only be called with a GIL.  NumPy had a few places with very unsafe sigint handling (not thread-safe).  But generally when we are in a situation that catching sigints would be nice as an enhancement, we do of course not hold the GIL.

So I am wondering if we can find some kind of thread-safe solution, or even just recipe.  Briefly looking at the code, it seemed to me that adding a new function with an additional `tstate` signature:

    PyOS_InterruptOccurred(PyThreadState *tstate)

Could work, and be a simple way to allow this in the future?  It is probably not high priority for us (NumPy had only one place where it tried to stop long running computations).
But right now I am unsure if the function has much use if it requires the GIL to be held and a `tstate=NULL` argument seemed reasonable (if it works), except that it adds a C-API name.
msg371887 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-19 14:59
Such function already exists in the master branch, but it's only part of the internal C API:

PyAPI_FUNC(int) _PyOS_InterruptOccurred(PyThreadState *tstate);

Currently, the C API design is to always requires to hold the GIL.
History
Date User Action Args
2022-04-11 14:59:32adminsetgithub: 85209
2020-06-19 14:59:23vstinnersetmessages: + msg371887
2020-06-19 14:11:55sebergcreate