diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-09-01 11:01:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-01 11:01:05 (GMT) |
commit | 353053d9ad08fea0e205e6c008b8a4350c0188e6 (patch) | |
tree | 3bd4434c152e934fb260c1c1651c080c3df29a14 /Modules/_threadmodule.c | |
parent | 6922b9e4fce635339cb94c2fdef6bba4e2a99621 (diff) | |
download | cpython-353053d9ad08fea0e205e6c008b8a4350c0188e6.zip cpython-353053d9ad08fea0e205e6c008b8a4350c0188e6.tar.gz cpython-353053d9ad08fea0e205e6c008b8a4350c0188e6.tar.bz2 |
[3.8] bpo-37994: Fix silencing all errors if an attribute lookup fails. (GH-15630) (GH-15635)
Only AttributeError should be silenced.
(cherry picked from commit 41c57b335330ff48af098d47e379e0f9ba09d233)
Diffstat (limited to 'Modules/_threadmodule.c')
-rw-r--r-- | Modules/_threadmodule.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index d5e40ef..fadf57a 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -1305,6 +1305,7 @@ static int thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value, PyObject *exc_traceback, PyObject *thread) { + _Py_IDENTIFIER(name); /* print(f"Exception in thread {thread.name}:", file=file) */ if (PyFile_WriteString("Exception in thread ", file) < 0) { return -1; @@ -1312,7 +1313,9 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value, PyObject *name = NULL; if (thread != Py_None) { - name = PyObject_GetAttrString(thread, "name"); + if (_PyObject_LookupAttrId(thread, &PyId_name, &name) < 0) { + return -1; + } } if (name != NULL) { if (PyFile_WriteObject(name, file, Py_PRINT_RAW) < 0) { @@ -1322,8 +1325,6 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value, Py_DECREF(name); } else { - PyErr_Clear(); - unsigned long ident = PyThread_get_thread_ident(); PyObject *str = PyUnicode_FromFormat("%lu", ident); if (str != NULL) { |