You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
threading._get_ident(): remove it in the doc or make it public #56237
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2011-05-30.21:04:22.473>created_at=<Date2011-05-07.10:24:44.959>labels= ['library', 'docs']
title='threading._get_ident(): remove it in the doc or make it public'updated_at=<Date2011-05-30.21:23:58.809>user='https://github.com/vstinner'
Oh, I misunderstood threading.py. current_thread().ident cannot be None.
During the bootstrap of a thread, Thread._ident is None, but current_thread().ident is not None because current_thread() creates a dummy thread object having the right identifer. This dummy object is destroyed at soon as the Thread object is started (see Thread._bootstrap_inner).
current_thread().ident is a little bit "suboptimal" because it gets the identifier of the thread, it reads the corresponding thread object, and then it gets the identifier of the thread object.
changed the title [-]threading._get_ident(): remove it in the doc and make it public[/-][+]threading._get_ident(): remove it in the doc or make it public[/+]on May 23, 2011
threading_get_ident.patch: make get_ident() public, replace threading._get_ident() by threading.get_ident().
According to this patch, get_ident() function *is* used: it is used by the logging and reprlib modules (and many tests). My patch avoids the usage of the low-level module, _thread_, in logging and reprlib.
I adapted signal.pthread_kill() documentation to replace threading.current_thread().ident by threading.get_ident().
Activity
vstinner commentedon May 7, 2011
I don't know why threading._get_ident() (which is _thread.get_ident()) is private: this function is safe.
This function becomes useful with pthread_kill() which will be added by bpo-8407.
vstinner commentedon May 7, 2011
I think that threading._get_ident() is more reliable than threading.current_thread().ident because Thread.ident can be None in some cases.
vstinner commentedon May 16, 2011
@pitrou: What do you think Antoine?
vstinner commentedon May 16, 2011
The threading API changed in Python 3 with the PEP-3108, especially and issue bpo-2875. Extract of the PEP:
"thread [done]
The issue was closed by the commit [7fe3a8648ce2], "Issue bpo-2875: Rename thread to _thread and dummy_thread to _dummy_thread."
pitrou commentedon May 16, 2011
In which case can it be None?
vstinner commentedon May 16, 2011
Oh, I misunderstood threading.py. current_thread().ident cannot be None.
During the bootstrap of a thread, Thread._ident is None, but current_thread().ident is not None because current_thread() creates a dummy thread object having the right identifer. This dummy object is destroyed at soon as the Thread object is started (see Thread._bootstrap_inner).
current_thread().ident is a little bit "suboptimal" because it gets the identifier of the thread, it reads the corresponding thread object, and then it gets the identifier of the thread object.
merwok commentedon May 23, 2011
I find it strange that you propose to make a function public and remove its doc :) Is a negative missing in the bug title?
[-]threading._get_ident(): remove it in the doc and make it public[/-][+]threading._get_ident(): remove it in the doc or make it public[/+]vstinner commentedon May 24, 2011
threading_get_ident.patch: make get_ident() public, replace threading._get_ident() by threading.get_ident().
According to this patch, get_ident() function *is* used: it is used by the logging and reprlib modules (and many tests). My patch avoids the usage of the low-level module, _thread_, in logging and reprlib.
I adapted signal.pthread_kill() documentation to replace threading.current_thread().ident by threading.get_ident().
python-dev commentedon May 30, 2011
New changeset 5548197d1f22 by Victor Stinner in branch 'default':
Close bpo-12028: Make threading._get_ident() public, rename it to
http://hg.python.org/cpython/rev/5548197d1f22
python-dev commentedon May 30, 2011
New changeset 6387aa6b496d by Victor Stinner in branch 'default':
Issue bpo-12028: fix NEWS entry
http://hg.python.org/cpython/rev/6387aa6b496d