]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
signalmodule.c uses _PyErr_WriteUnraisableMsg() (#98217)
authorVictor Stinner <vstinner@python.org>
Wed, 12 Oct 2022 15:26:58 +0000 (17:26 +0200)
committerGitHub <noreply@github.com>
Wed, 12 Oct 2022 15:26:58 +0000 (17:26 +0200)
Signal wakeup fd errors are now logged with
_PyErr_WriteUnraisableMsg(), rather than PySys_WriteStderr() and
PyErr_WriteUnraisable(), to pass the error message to
sys.unraisablehook. By default, it's still written into stderr (unless
sys.unraisablehook is overriden).

Modules/signalmodule.c

index b85d6d19e8cd057c532cacb9ca54a8253b575a1f..bdd3f4b2204ef4fcba0bb0c843719fe1d5686e97 100644 (file)
@@ -272,9 +272,8 @@ report_wakeup_write_error(void *data)
     errno = (int) (intptr_t) data;
     PyErr_Fetch(&exc, &val, &tb);
     PyErr_SetFromErrno(PyExc_OSError);
-    PySys_WriteStderr("Exception ignored when trying to write to the "
-                      "signal wakeup fd:\n");
-    PyErr_WriteUnraisable(NULL);
+    _PyErr_WriteUnraisableMsg("when trying to write to the signal wakeup fd",
+                              NULL);
     PyErr_Restore(exc, val, tb);
     errno = save_errno;
     return 0;
@@ -284,15 +283,15 @@ report_wakeup_write_error(void *data)
 static int
 report_wakeup_send_error(void* data)
 {
+    int send_errno = (int) (intptr_t) data;
+
     PyObject *exc, *val, *tb;
     PyErr_Fetch(&exc, &val, &tb);
     /* PyErr_SetExcFromWindowsErr() invokes FormatMessage() which
        recognizes the error codes used by both GetLastError() and
        WSAGetLastError */
-    PyErr_SetExcFromWindowsErr(PyExc_OSError, (int) (intptr_t) data);
-    PySys_WriteStderr("Exception ignored when trying to send to the "
-                      "signal wakeup fd:\n");
-    PyErr_WriteUnraisable(NULL);
+    PyErr_SetExcFromWindowsErr(PyExc_OSError, send_errno);
+    _PyErr_WriteUnraisableMsg("when trying to send to the signal wakeup fd", NULL);
     PyErr_Restore(exc, val, tb);
     return 0;
 }