Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix :obj:`threading.Thread.is_alive` to remain ``True`` until the underlying OS
thread is fully cleaned up. This avoids false negatives in edge cases
involving thread monitoring or premature :obj:`threading.Thread.is_alive` calls.
9 changes: 6 additions & 3 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,9 @@ ThreadHandle_start(ThreadHandle *self, PyObject *func, PyObject *args,
}

static int
join_thread(ThreadHandle *handle)
join_thread(void *arg)
{
ThreadHandle *handle = (ThreadHandle*)arg;
assert(get_thread_handle_state(handle) == THREAD_HANDLE_RUNNING);
PyThread_handle_t os_handle;
if (ThreadHandle_get_os_handle(handle, &os_handle)) {
Expand Down Expand Up @@ -528,8 +529,7 @@ ThreadHandle_join(ThreadHandle *self, PyTime_t timeout_ns)
}
}

if (_PyOnceFlag_CallOnce(&self->once, (_Py_once_fn_t *)join_thread,
self) == -1) {
if (_PyOnceFlag_CallOnce(&self->once, join_thread, self) == -1) {
return -1;
}
assert(get_thread_handle_state(self) == THREAD_HANDLE_DONE);
Expand Down Expand Up @@ -657,6 +657,9 @@ PyThreadHandleObject_is_done(PyThreadHandleObject *self,
PyObject *Py_UNUSED(ignored))
{
if (_PyEvent_IsSet(&self->handle->thread_is_exiting)) {
if (_PyOnceFlag_CallOnce(&self->handle->once, join_thread, self->handle) == -1) {
return NULL;
}
Py_RETURN_TRUE;
}
else {
Expand Down