
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2009-07-21 14:25 bysargo, last changed2022-04-11 14:56 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| thread_id_unsigned.patch | serhiy.storchaka,2013-02-06 14:38 | review | ||
| thread_id_unsigned_3.patch | serhiy.storchaka,2015-02-18 07:27 | review | ||
| thread_id_unsigned_4.patch | serhiy.storchaka,2015-02-18 12:34 | review | ||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 781 | merged | serhiy.storchaka,2017-03-23 11:07 | |
| Messages (12) | |||
|---|---|---|---|
| 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.6Proposal:In my opinion code that cast value returned by pthread_self() should bechanged (see:Python/thread_pthread.h).Other possibility is to change only returned value by get_identfunction. 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. Ifthe same application uses some C library that also writes in log filesome 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 integerhttp://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).aspxOops, 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() inPython/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 changesetaefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5 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 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:56:51 | admin | set | github: 50781 |
| 2017-03-24 17:22:55 | serhiy.storchaka | set | status: open -> closed assignee:serhiy.storchaka stage: patch review -> resolved resolution: fixed versions: + Python 3.7, - Python 3.5 |
| 2017-03-24 16:32:00 | vstinner | set | messages: +msg290096 |
| 2017-03-23 11:07:48 | serhiy.storchaka | set | pull_requests: +pull_request685 |
| 2015-02-18 12:34:31 | serhiy.storchaka | set | files: +thread_id_unsigned_4.patch messages: +msg236169 |
| 2015-02-18 08:31:49 | vstinner | set | messages: +msg236166 |
| 2015-02-18 07:27:52 | serhiy.storchaka | set | files: +thread_id_unsigned_3.patch messages: +msg236165 |
| 2015-02-17 23:59:19 | vstinner | set | nosy: +vstinner messages: +msg236157 versions: + Python 3.5, - Python 2.7, Python 3.2, Python 3.3, Python 3.4 |
| 2014-02-03 18:40:59 | BreamoreBoy | set | nosy: -BreamoreBoy |
| 2013-02-06 18:07:53 | pitrou | set | messages: +msg181548 |
| 2013-02-06 14:38:16 | serhiy.storchaka | set | files: +thread_id_unsigned.patch keywords: +patch messages: +msg181526 stage: needs patch -> patch review |
| 2013-02-06 10:09:21 | serhiy.storchaka | set | nosy: +serhiy.storchaka versions: + Python 3.3, Python 3.4, - Python 3.1 |
| 2011-01-05 18:17:00 | pitrou | set | nosy:gregory.p.smith,amaury.forgeotdarc,pitrou,rnk,sargo,BreamoreBoy messages: +msg125445 |
| 2011-01-05 18:07:47 | amaury.forgeotdarc | set | nosy: +amaury.forgeotdarc messages: +msg125443 |
| 2011-01-05 18:03:37 | pitrou | set | nosy: +gregory.p.smith,rnk,pitrou messages: +msg125442 |
| 2010-08-01 10:01:59 | BreamoreBoy | set | type: behavior components: + Extension Modules, - Library (Lib) versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6, Python 2.5, Python 2.4 nosy: +BreamoreBoy messages: +msg112303 stage: needs patch |
| 2009-07-21 14:25:21 | sargo | create | |