[issue42969] pthread_exit & PyThread_exit_thread from PyEval_RestoreThread etc. are harmful

Jeremy Maitin-Shepard report at bugs.python.org
Fri Sep 24 11:24:27 EDT 2021


Jeremy Maitin-Shepard <jeremy at jeremyms.com> added the comment:

To be clear, the problem I'm trying to address here is not specific to embedding Python in a C++ application.  In fact the issue came to my attention while using Python directly, but loading an extension module that was written in C++ using the popular pybind11 library.

If we continue having Python call `pthread_exit` and `_endthreadex`, we are imposing strong constraints on call stacks that call the Python API.  Granted, hanging a thread is also not something a well-behaved library should do, but it is at least slightly better than killing the thread.  In a sense hanging is also logical, since the thread has requested to block until the GIL can be acquired, and the GIL cannot be acquired.

I have described a number of problems caused by `pthread_exit`/`_endthreadex` that are fixed by hanging.  Can you help me understand what problems caused by hanging are fixed by `pthread_exit`/`_endthreadex`, that leads you to think it is a better default?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42969>
_______________________________________


More information about the Python-bugs-list mailing list