Jeremy Maitin-Shepard <jer...@jeremyms.com> added the comment:

Yes, I would agree that the new APIs are a useful addition regardless of the 
PyThread_exit_thread change.

As far as the proposed `Py_SetThreadExitCallback` that seems like a fine thing 
for applications to use, as long as it doesn't impact how extensions need to be 
written to be safe from crashes/memory corruption.  So for example if the 
default is to hang, then changing it to log and then hang, or optionally log 
and terminate the program, would be fine, since extensions aren't affected 
either way.

Conversely, if one of the possible behaviors may be `_endthreadex` or 
`pthread_exit`, then libraries must be written to be safe under that behavior 
anyway, which is unfortunate.  Furthermore, say for a library that only 
supports POSIX, maybe it is written to be safe under `pthread_exit` because it 
uses destructors to do cleanup, but then it will cause deadlock if the callback 
chooses to hang the thread instead.  Thus, I think allowing the callback to 
change the behavior in a way that could impact extensions is not a great idea.

The callback also doesn't seem like a very good mechanism for an extension that 
is incompatible with `pthread_exit` or `_endthreadex`, such as one using 
pybind11, to try to mitigate that problem, since an individual library 
shouldn't be changing application-wide behavior unless the library is 
specifically being used by the application for that purpose.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42969>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to