Message401922
> Change CPython to call abort() instead of pthread_exit() as that situation is unresolvable and the process dying is better than hanging, partially alive. That solution isn't friendly, but is better than being silent and allowing deadlock. A failing process is always better than a hung process, especially a partially hung process.
The last time someone proposed to always call abort(), I proposed to add a hook instead: I added sys.unraisablehook. See bpo-36829.
If we adopt this option, it can be a callback in C, something like: Py_SetThreadExitCallback(func) which would call func() rather than pthread_exit() in ceval.c.
--
Another option would be to add an option to disable daemon thread.
concurrent.futures has been modified to no longer use daemon threads: bpo-39812.
It is really hard to write a reliable implementation of daemon threads with Python subintepreters. See bpo-40234 "[subinterpreters] Disallow daemon threads in subinterpreters optionally".
There is already a private flag for that in subinterpreters to disallow spawning processes or threads: an "isolated" subintepreter. Example with _thread.start_new_thread():
PyInterpreterState *interp = _PyInterpreterState_GET();
if (interp->config._isolated_interpreter) {
PyErr_SetString(PyExc_RuntimeError,
"thread is not supported for isolated subinterpreters");
return NULL;
}
Or os.fork():
if (interp->config._isolated_interpreter) {
PyErr_SetString(PyExc_RuntimeError,
"fork not supported for isolated subinterpreters");
return NULL;
}
See also my article on fixing crashes with daemon threads:
* https://vstinner.github.io/gil-bugfixes-daemon-threads-python39.html
* https://vstinner.github.io/daemon-threads-python-finalization-python32.html |
|
Date |
User |
Action |
Args |
2021-09-16 07:31:55 | vstinner | set | recipients:
+ vstinner, gregory.p.smith, izbyshev, jbms |
2021-09-16 07:31:55 | vstinner | set | messageid: <1631777515.52.0.710176711974.issue42969@roundup.psfhosted.org> |
2021-09-16 07:31:55 | vstinner | link | issue42969 messages |
2021-09-16 07:31:55 | vstinner | create | |
|