Skip to content

Commit

Permalink
Add handles to shutdown list before starting the thread
Browse files Browse the repository at this point in the history
  • Loading branch information
mpage committed Mar 11, 2024
1 parent ccd1c2e commit 180300c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1737,14 +1737,20 @@ do_start_new_thread(thread_module_state *state, PyObject *func, PyObject *args,
return -1;
}

if (ThreadHandle_start(handle, func, args, kwargs) < 0) {
return -1;
}

if (!daemon) {
// Add the handle before starting the thread to avoid adding a handle
// to a thread that has already finished (i.e. if the thread finishes
// before the call to `ThreadHandle_start()` below returns).
add_to_shutdown_handles(state, handle);
}

if (ThreadHandle_start(handle, func, args, kwargs) < 0) {
if (!daemon) {
remove_from_shutdown_handles(handle);
}
return -1;
}

return 0;
}

Expand Down

0 comments on commit 180300c

Please sign in to comment.