msg90761 - (view) |
Author: Wojciech Lichota (sargo) |
Date: 2009-07-21 14:25 |
In glibc library (on linux) pthread_t is defined as: typedef unsigned long int pthread_t; But python thread module interprets this value as signed long. Reproduce: >>> import thread >>> thread.get_ident() In some cases it returns negative value. Checked in python 2.4, 2.5, 2.6 Proposal: In my opinion code that cast value returned by pthread_self() should be changed (see: Python/thread_pthread.h). Other possibility is to change only returned value by get_ident function. In this case it should use PyLong_FromUnsignedLong (see: Modules/threadmodule.c). Background: logging module uses 'thread.get_ident()' to save thread_id in logs. If the same application uses some C library that also writes in log file some info with thread_id, in some situations this numbers are diffrent. This complicate logs analyze. |
|
|
msg112303 - (view) |
Author: Mark Lawrence (BreamoreBoy) * |
Date: 2010-08-01 10:01 |
Can a C guru comment on this please. |
|
|
msg125442 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2011-01-05 18:03 |
Well, the issue is that signedness differs depending on the platform. Under Windows, thread ids are signed (DWORD). Satisfying all cases would complicate things quite a bit. |
|
|
msg125443 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) *  |
Date: 2011-01-05 18:07 |
no, DWORD is a 32-bit unsigned integer http://msdn.microsoft.com/en-us/library/aa383751(VS.85).aspx |
|
|
msg125445 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2011-01-05 18:17 |
> no, DWORD is a 32-bit unsigned integer > http://msdn.microsoft.com/en-us/library/aa383751(VS.85).aspx Oops, my bad. |
|
|
msg181526 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-02-06 14:38 |
Here is a patch, which made all thread id to be unsigned. |
|
|
msg181548 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2013-02-06 18:07 |
You could add a test for it. |
|
|
msg236157 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2015-02-17 23:59 |
On Linux, the following C program tells me that pthread_t is unsigned. --- #include <pthread.h> #include <stdio.h> #define TYPE_IS_SIGNED(TYPE) ((TYPE)-1 < (TYPE)0) int main() { printf("signed? %i\n", TYPE_IS_SIGNED(pthread_t)); return 0; } --- So it's fair to modify threading.get_ident() to return an unsigned number. But I disagree to change stable Python versions, it may break applications. Oh, I wrote write_thread_id() in Python/traceback.c and this function already casts the thread identifier to an unsigned number ;-) |
|
|
msg236165 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-02-18 07:27 |
Here is updated patch. Added few tests. |
|
|
msg236166 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2015-02-18 08:31 |
> Here is updated patch. Added few tests. Cool. I sent a review. |
|
|
msg236169 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-02-18 12:34 |
Thank you Victor for your review. Here is updated patch. |
|
|
msg290096 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2017-03-24 16:32 |
New changeset aefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5 by Victor Stinner (Serhiy Storchaka) in branch 'master': bpo-6532: Make the thread id an unsigned integer. (#781) https://github.com/python/cpython/commit/aefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5 |
|
|