From addfa2b202634efa1b12e21b4d7a6954e1a98d75 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Thu, 13 Nov 2025 18:07:47 +0000 Subject: [PATCH 1/4] PyOS_InterruptOccurred --- Doc/c-api/sys.rst | 10 ++++++++++ Modules/signalmodule.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/sys.rst b/Doc/c-api/sys.rst index 336e3ef96400f4..df1ecc6b4a64d8 100644 --- a/Doc/c-api/sys.rst +++ b/Doc/c-api/sys.rst @@ -123,6 +123,16 @@ Operating System Utilities This is a thin wrapper around either :c:func:`!sigaction` or :c:func:`!signal`. Do not call those functions directly! + +.. c:function:: int PyOS_InterruptOccurred(void) + + Check if a :c:macro:`!SIGINT` signal has been received. + Returns ``1`` if a :c:macro:`!SIGINT` has occurred and clears the signal flag, + or ``0`` otherwise. + + The caller must hold an :term:`attached thread state`. + + .. c:function:: wchar_t* Py_DecodeLocale(const char* arg, size_t *size) .. warning:: diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 4d0e224ff757e7..efb557987e861d 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -2025,7 +2025,7 @@ _PyOS_InterruptOccurred(PyThreadState *tstate) } -// The caller must to hold the GIL +// The caller must hold the GIL int PyOS_InterruptOccurred(void) { From 79356fdae01aaeec847aeb4d98837d0bdedf3907 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Thu, 13 Nov 2025 18:51:54 +0000 Subject: [PATCH 2/4] Commit --- Doc/c-api/sys.rst | 7 +++++++ Modules/signalmodule.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/sys.rst b/Doc/c-api/sys.rst index df1ecc6b4a64d8..20ad3ba1c1839f 100644 --- a/Doc/c-api/sys.rst +++ b/Doc/c-api/sys.rst @@ -130,8 +130,15 @@ Operating System Utilities Returns ``1`` if a :c:macro:`!SIGINT` has occurred and clears the signal flag, or ``0`` otherwise. + This function is async-signal-safe. The caller must hold an :term:`attached thread state`. + In most cases, you should prefer :c:func:`PyErr_CheckSignals` over this function. + :c:func:`!PyErr_CheckSignals` invokes the appropriate signal handlers + for all pending signals, allowing Python code to handle the signal properly. + This function only detects :c:macro:`!SIGINT` and does not invoke any Python + signal handlers. + .. c:function:: wchar_t* Py_DecodeLocale(const char* arg, size_t *size) diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index efb557987e861d..4d0e224ff757e7 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -2025,7 +2025,7 @@ _PyOS_InterruptOccurred(PyThreadState *tstate) } -// The caller must hold the GIL +// The caller must to hold the GIL int PyOS_InterruptOccurred(void) { From 56cc3845d783e16f01927ca47305eabf5722f0d4 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Thu, 13 Nov 2025 19:26:19 +0000 Subject: [PATCH 3/4] Review --- Doc/c-api/sys.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/sys.rst b/Doc/c-api/sys.rst index 20ad3ba1c1839f..45fcdee7635f12 100644 --- a/Doc/c-api/sys.rst +++ b/Doc/c-api/sys.rst @@ -130,7 +130,7 @@ Operating System Utilities Returns ``1`` if a :c:macro:`!SIGINT` has occurred and clears the signal flag, or ``0`` otherwise. - This function is async-signal-safe. + This function is async-signal-safe and this function cannot fail. The caller must hold an :term:`attached thread state`. In most cases, you should prefer :c:func:`PyErr_CheckSignals` over this function. From b4e096a0c569c987ec79028e214d2735663a6862 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Fri, 14 Nov 2025 07:35:44 +0000 Subject: [PATCH 4/4] Review --- Doc/c-api/sys.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/sys.rst b/Doc/c-api/sys.rst index 45fcdee7635f12..ee73c1c8adaa7b 100644 --- a/Doc/c-api/sys.rst +++ b/Doc/c-api/sys.rst @@ -127,18 +127,19 @@ Operating System Utilities .. c:function:: int PyOS_InterruptOccurred(void) Check if a :c:macro:`!SIGINT` signal has been received. + Returns ``1`` if a :c:macro:`!SIGINT` has occurred and clears the signal flag, or ``0`` otherwise. - This function is async-signal-safe and this function cannot fail. - The caller must hold an :term:`attached thread state`. - In most cases, you should prefer :c:func:`PyErr_CheckSignals` over this function. :c:func:`!PyErr_CheckSignals` invokes the appropriate signal handlers for all pending signals, allowing Python code to handle the signal properly. This function only detects :c:macro:`!SIGINT` and does not invoke any Python signal handlers. + This function is async-signal-safe and this function cannot fail. + The caller must hold an :term:`attached thread state`. + .. c:function:: wchar_t* Py_DecodeLocale(const char* arg, size_t *size)