-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
bpo-36084: add native thread ID (TID) to threading.Thread objects #11993
Conversation
…jects now have a tid property (kernel thread ID)
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
…c operation, since the functionality now supports Windows as well; cleaned up and clarified doc notes, updated version added number (3.8)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On POSIX platforms, pthread_create returns the thread ID, which seems more robust, clean, and it should work on ALL POSIX platforms, not just mac and Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried this on my machine (F29) - works great.
May I suggest to add some tests, e.g. skoslowski@795643a
@datalogics-robb do you think this change is necessary? Looking further into the C side of things, the mechanism for creating threads relies upon returning (what becomes) the thread's
@skoslowski Great idea! – I'll add those tests and commit shortly. |
If you are talking about the first parameter of pthread_create(): it is returned by PyThread_start_new_thread() which is then returned by _thread.start_new_thread(). threading.Thread ignores _thread.start_new_thread() result. |
@vstinner The value returned from Also, see here for why the |
Also per @vstinner –
I am now looking into FreeBSD support, as I understand the mechanism is different than on Linux/POSIX machines. I believe it should not be too difficult to implement. (famous last words? haha) Assuming this PR will support Windows, Linux, Mac, and FreeBSD, are there any other major architectures missing that should be added (archs where Python threading is supported)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this. Here are some comments.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Where is that? According to POSIX, "If successful, the pthread_create() function shall return zero; otherwise, an error number shall be returned to indicate the error." |
From @pitrou
All –
To clarify, the ID returned via the first argument in the call to This is not the same identifier as the one created by |
Yes, so there are two problems with the
|
Per @bedevere-bot – |
Thanks for making the requested changes! @pitrou: please review the changes made to this pull request. |
Should the commit history be squashed prior to merge? |
@jaketesler We let Github squash automatically when merging, so you needn't do it yourself. |
This functionality adds a native Thread ID to threading.Thread objects. This ID (
TID
), similar to thePID
of a process, is assigned by the OS (kernel) and is generally used for externally monitoring resources consumed by the running thread (or process).This does not replace the
ident
attribute within Thread objects, which is assigned by the Python interpreter and is guaranteed as unique for the lifetime of the Python instance.This new functionality fully supports Linux, Apple, and Windows platforms.
https://bugs.python.org/issue36084