-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
threading Thread.join should call the OS join API #110829
Comments
On Windows, we start the thread with But, of course, on Windows the entire fork() problem doesn't exist, so it's less of a problem if we don't provide lesser guarantees. Note that right now we detach the thread as soon as it is started, so we may want to expose a different internal API that doesn't detach the thread. |
FWIW, the gap between Python-thread-ends and OS-thread-exits bit me after I added the per-interpreter GIL (PEP 684). We ended up with crash due to that interval (a race in the GIL's |
The API added here is only for the |
Joining a thread now ensures the underlying OS thread has exited. This is required for safer fork() in multi-threaded processes. --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Closing as the PR has been merged. |
Oops, sorry for forgetting to close this issue! |
Feature or enhancement
Proposal:
threading.Thread.join()
only waits for the CPython internals to wash its hands of the underlying thread. It doesn't actually wait for the OS thread itself to exit, which in theory happens rapidly as its final internal code completes quickly - but we have no good wait to determine.Why finally do this now? Now that we're encouraging people to notice and avoid threading existing when
os.fork
is called in 3.12, a use case has come up for deterministically knowing when the thread is done at the OS level so that the code can proceed withos.fork
.#110510 could use this in an atfork before fork handler for example.
POSIX has pthread_join, we should be able to expose and use via
_thread
. Windows presumably has an equivalent concept API.Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: