mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
gh-136003: Execute pre-finalization callbacks in a loop (GH-136004)
This commit is contained in:
parent
d6a6fe2a5b
commit
2191497933
9 changed files with 281 additions and 43 deletions
|
|
@ -429,7 +429,7 @@ force_done(void *arg)
|
|||
|
||||
static int
|
||||
ThreadHandle_start(ThreadHandle *self, PyObject *func, PyObject *args,
|
||||
PyObject *kwargs)
|
||||
PyObject *kwargs, int daemon)
|
||||
{
|
||||
// Mark the handle as starting to prevent any other threads from doing so
|
||||
PyMutex_Lock(&self->mutex);
|
||||
|
|
@ -453,7 +453,8 @@ ThreadHandle_start(ThreadHandle *self, PyObject *func, PyObject *args,
|
|||
goto start_failed;
|
||||
}
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
boot->tstate = _PyThreadState_New(interp, _PyThreadState_WHENCE_THREADING);
|
||||
uint8_t whence = daemon ? _PyThreadState_WHENCE_THREADING_DAEMON : _PyThreadState_WHENCE_THREADING;
|
||||
boot->tstate = _PyThreadState_New(interp, whence);
|
||||
if (boot->tstate == NULL) {
|
||||
PyMem_RawFree(boot);
|
||||
if (!PyErr_Occurred()) {
|
||||
|
|
@ -1916,7 +1917,7 @@ do_start_new_thread(thread_module_state *state, PyObject *func, PyObject *args,
|
|||
add_to_shutdown_handles(state, handle);
|
||||
}
|
||||
|
||||
if (ThreadHandle_start(handle, func, args, kwargs) < 0) {
|
||||
if (ThreadHandle_start(handle, func, args, kwargs, daemon) < 0) {
|
||||
if (!daemon) {
|
||||
remove_from_shutdown_handles(handle);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue