STINNER Victor <vstin...@python.org> added the comment:

> 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

----------

_______________________________________
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