[Python-checkins] bpo-44434: Don't call PyThread_exit_thread() explicitly (GH-26758)

vstinner webhook-mailer at python.org
Mon Jun 21 07:16:22 EDT 2021


https://github.com/python/cpython/commit/45a78f906d2d5fe5381d78466b11763fc56d57ba
commit: 45a78f906d2d5fe5381d78466b11763fc56d57ba
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2021-06-21T13:16:18+02:00
summary:

bpo-44434: Don't call PyThread_exit_thread() explicitly (GH-26758)

_thread.start_new_thread() no longer calls PyThread_exit_thread()
explicitly at the thread exit, the call was redundant.

On Linux with the glibc, pthread_cancel() loads dynamically the
libgcc_s.so.1 library. dlopen() can fail if there is no more
available file descriptor to open the file. In this case, the process
aborts with the error message:

"libgcc_s.so.1 must be installed for pthread_cancel to work"

pthread_cancel() unwinds back to the thread's wrapping function that
calls the thread entry point.

The unwind function is dynamically loaded from the libgcc_s library
since it is tightly coupled to the C compiler (GCC). The unwinder
depends on DWARF, the compiler generates DWARF, so the unwinder
belongs to the compiler.

Thanks Florian Weimer and Carlos O'Donell for their help on
investigating this issue.

files:
A Misc/NEWS.d/next/Library/2021-06-16-16-52-14.bpo-44434.SQS4Pg.rst
M Modules/_threadmodule.c

diff --git a/Misc/NEWS.d/next/Library/2021-06-16-16-52-14.bpo-44434.SQS4Pg.rst b/Misc/NEWS.d/next/Library/2021-06-16-16-52-14.bpo-44434.SQS4Pg.rst
new file mode 100644
index 0000000000000..37b5b57ce6569
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-06-16-16-52-14.bpo-44434.SQS4Pg.rst
@@ -0,0 +1,4 @@
+_thread.start_new_thread() no longer calls PyThread_exit_thread() explicitly
+at the thread exit, the call was redundant. On Linux with the glibc,
+pthread_exit() aborts the whole process if dlopen() fails to open
+libgcc_s.so file (ex: EMFILE error). Patch by Victor Stinner.
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index bee69f2099c0e..5b5d2c5b03ec3 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -1110,7 +1110,9 @@ thread_run(void *boot_raw)
     PyThreadState_Clear(tstate);
     _PyThreadState_DeleteCurrent(tstate);
 
-    PyThread_exit_thread();
+    // bpo-44434: Don't call explicitly PyThread_exit_thread(). On Linux with
+    // the glibc, pthread_exit() can abort the whole process if dlopen() fails
+    // to open the libgcc_s.so library (ex: EMFILE error).
 }
 
 static PyObject *



More information about the Python-checkins mailing list