Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue6532

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:thread.get_ident() should return unsigned value
Type:behaviorStage:resolved
Components:Extension ModulesVersions:Python 3.7
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: serhiy.storchakaNosy List: amaury.forgeotdarc, gregory.p.smith, pitrou, rnk, sargo, serhiy.storchaka, vstinner
Priority:normalKeywords:patch

Created on2009-07-21 14:25 bysargo, last changed2022-04-11 14:56 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
thread_id_unsigned.patchserhiy.storchaka,2013-02-06 14:38review
thread_id_unsigned_3.patchserhiy.storchaka,2015-02-18 07:27review
thread_id_unsigned_4.patchserhiy.storchaka,2015-02-18 12:34review
Pull Requests
URLStatusLinkedEdit
PR 781mergedserhiy.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)*(Python committer)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)*(Python committer)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)*(Python committer)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)*(Python committer)Date: 2013-02-06 14:38
Here is a patch, which made all thread id to be unsigned.
msg181548 -(view)Author: Antoine Pitrou (pitrou)*(Python committer)Date: 2013-02-06 18:07
You could add a test for it.
msg236157 -(view)Author: STINNER Victor (vstinner)*(Python committer)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)*(Python committer)Date: 2015-02-18 07:27
Here is updated patch. Added few tests.
msg236166 -(view)Author: STINNER Victor (vstinner)*(Python committer)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)*(Python committer)Date: 2015-02-18 12:34
Thank you Victor for your review. Here is updated patch.
msg290096 -(view)Author: STINNER Victor (vstinner)*(Python committer)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
DateUserActionArgs
2022-04-11 14:56:51adminsetgithub: 50781
2017-03-24 17:22:55serhiy.storchakasetstatus: open -> closed
assignee:serhiy.storchaka
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.7, - Python 3.5
2017-03-24 16:32:00vstinnersetmessages: +msg290096
2017-03-23 11:07:48serhiy.storchakasetpull_requests: +pull_request685
2015-02-18 12:34:31serhiy.storchakasetfiles: +thread_id_unsigned_4.patch

messages: +msg236169
2015-02-18 08:31:49vstinnersetmessages: +msg236166
2015-02-18 07:27:52serhiy.storchakasetfiles: +thread_id_unsigned_3.patch

messages: +msg236165
2015-02-17 23:59:19vstinnersetnosy: +vstinner

messages: +msg236157
versions: + Python 3.5, - Python 2.7, Python 3.2, Python 3.3, Python 3.4
2014-02-03 18:40:59BreamoreBoysetnosy: -BreamoreBoy
2013-02-06 18:07:53pitrousetmessages: +msg181548
2013-02-06 14:38:16serhiy.storchakasetfiles: +thread_id_unsigned.patch
keywords: +patch
messages: +msg181526

stage: needs patch -> patch review
2013-02-06 10:09:21serhiy.storchakasetnosy: +serhiy.storchaka

versions: + Python 3.3, Python 3.4, - Python 3.1
2011-01-05 18:17:00pitrousetnosy:gregory.p.smith,amaury.forgeotdarc,pitrou,rnk,sargo,BreamoreBoy
messages: +msg125445
2011-01-05 18:07:47amaury.forgeotdarcsetnosy: +amaury.forgeotdarc
messages: +msg125443
2011-01-05 18:03:37pitrousetnosy: +gregory.p.smith,rnk,pitrou
messages: +msg125442
2010-08-01 10:01:59BreamoreBoysettype: 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:21sargocreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp