Message338826
Currently PyEval_RestoreThread and its callers (mainly PyGILState_Ensure) can terminate the thread if the interpreter is finalizing:
PyEval_RestoreThread(PyThreadState *tstate)
{
if (tstate == NULL)
Py_FatalError("PyEval_RestoreThread: NULL tstate");
assert(gil_created());
int err = errno;
take_gil(tstate);
/* _Py_Finalizing is protected by the GIL */
if (_Py_IsFinalizing() && !_Py_CURRENTLY_FINALIZING(tstate)) {
drop_gil(tstate);
PyThread_exit_thread();
Py_UNREACHABLE();
}
errno = err;
PyThreadState_Swap(tstate);
}
This behaviour that protects against problems due to daemon threads registered with the interpreter can be *very* surprising for C-extensions that are using these functions to implement callbacks that can call into Python. These callbacks threads are not owned by the interpreter and are usually joined by someone else, ending in deadlocks in many situations.
I propose to add a warning to the documentation to inform users about this situation. |
|
Date |
User |
Action |
Args |
2019-03-25 22:14:35 | pablogsal | set | recipients:
+ pablogsal, pitrou, vstinner, eric.snow |
2019-03-25 22:14:35 | pablogsal | set | messageid: <1553552075.96.0.382616254369.issue36427@roundup.psfhosted.org> |
2019-03-25 22:14:35 | pablogsal | link | issue36427 messages |
2019-03-25 22:14:35 | pablogsal | create | |
|