Skip to content

Commit 6614eac

Browse files
bpo-44434: Don't call PyThread_exit_thread() explicitly (GH-26758) (GH-26824)
_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. (cherry picked from commit 45a78f9) Co-authored-by: Victor Stinner <[email protected]>
1 parent 9b0bbb9 commit 6614eac

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
_thread.start_new_thread() no longer calls PyThread_exit_thread() explicitly
2+
at the thread exit, the call was redundant. On Linux with the glibc,
3+
pthread_exit() aborts the whole process if dlopen() fails to open
4+
libgcc_s.so file (ex: EMFILE error). Patch by Victor Stinner.

Modules/_threadmodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,9 @@ thread_run(void *boot_raw)
11051105
PyThreadState_Clear(tstate);
11061106
_PyThreadState_DeleteCurrent(tstate);
11071107

1108-
PyThread_exit_thread();
1108+
// bpo-44434: Don't call explicitly PyThread_exit_thread(). On Linux with
1109+
// the glibc, pthread_exit() can abort the whole process if dlopen() fails
1110+
// to open the libgcc_s.so library (ex: EMFILE error).
11091111
}
11101112

11111113
static PyObject *

0 commit comments

Comments
 (0)