-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
thread names : linux and windows support #1559
base: master
Are you sure you want to change the base?
Conversation
…windows 10 version of the library on a windows < 10 machine)
@giampaolo I allow myself to ping you, since no one reacted in 2 months Did you give a look to the patch? Thank you very much! |
Hello. No I didn’t have time to look at the patch (and I will still be busy for a while), but in principle I agree it would be good to have thread names. If in the meantime you could take a look at BSD and OSX implementation that would be great. |
I no longer have access to a OSX machine :( See my comments on psutil/_psutil_osx.c |
Can you please remove the demos and other unnecessary stuff? |
Done. Not sure about what's making the CI fail though |
@@ -1914,7 +1913,12 @@ def threads(self): | |||
values = st.split(b' ') | |||
utime = float(values[11]) / CLOCK_TICKS | |||
stime = float(values[12]) / CLOCK_TICKS | |||
ntuple = _common.pthread(int(thread_id), utime, stime) | |||
try: | |||
with open_binary("%s/comm" % tdir) as fcomm: |
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.
you shoud use open_text
instead
} | ||
get_thread_desc = (get_thread_desc_t) GetProcAddress( | ||
GetModuleHandle("Kernel32.dll"), "GetThreadDescription" | ||
); |
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.
This stuff should be done differently.
You should first define the prototype of GetThreadDescription
in psutil/arch/windows/ntext.h
then load GetThreadDescription
and set it as a global name in psutil/_psutil_common.c
.
This patch adds support for thread names on Linux and Windows, by adding an attribute name within the tuple returned by
psutil.threads()
On other operating system, the string is empty
The code is probably over-commented, we can clean this.
1 - Shall we remove the MacOSX comments, or add them as a comment of this PR?
2 - Remove the thread-names-demo/ folder, which is only here giving some small sample program to be tested
3 - Here is another way of naming thread in Windows, to have thread names appearing in Visual Studio debugger:
https://blogs.msdn.microsoft.com/stevejs/2005/12/20/naming-threads-in-win32-and-net/
I think the debugger see the exception while reading process's task, and interpret the exception message as the thread name.
The
SetThreadDescription()
call is really likely to be used to name threads now.4 - Do we really reject the use of unicode string? C.f psutil/tests/test_contracts.py:194
We probably want them on the name field, since Windows thread names are wide characters string.
Please, note that a previous thread name support implementation was tried.
This patch is originally inspired by this pull-request: #1135
on which both UbiCastTeam and fthiery worked.