mirror of
https://github.com/python/cpython.git
synced 2025-07-29 14:15:07 +00:00
change threading.getIdent to a property
This is new in 2.6 so now need to worry about backwards compatibility :)
This commit is contained in:
parent
e5bdccc77b
commit
d8a8972ca9
4 changed files with 9 additions and 8 deletions
|
@ -661,12 +661,12 @@ impossible to detect the termination of alien threads.
|
||||||
constructor.
|
constructor.
|
||||||
|
|
||||||
|
|
||||||
.. method:: Thread.get_ident()
|
.. attribute:: Thread.ident
|
||||||
|
|
||||||
Return the 'thread identifier' of this thread or None if the thread has not
|
The 'thread identifier' of this thread or ``None`` if the thread has not been
|
||||||
been started. This is a nonzero integer. See the :func:`thread.get_ident()`
|
started. This is a nonzero integer. See the :func:`thread.get_ident()`
|
||||||
function. Thread identifiers may be recycled when a thread exits and another
|
function. Thread identifiers may be recycled when a thread exits and another
|
||||||
thread is created. The identifier is returned even after the thread has
|
thread is created. The identifier is available even after the thread has
|
||||||
exited.
|
exited.
|
||||||
|
|
||||||
.. versionadded:: 2.6
|
.. versionadded:: 2.6
|
||||||
|
|
|
@ -73,7 +73,7 @@ class ThreadTests(unittest.TestCase):
|
||||||
for i in range(NUMTASKS):
|
for i in range(NUMTASKS):
|
||||||
t = TestThread("<thread %d>"%i, self, sema, mutex, numrunning)
|
t = TestThread("<thread %d>"%i, self, sema, mutex, numrunning)
|
||||||
threads.append(t)
|
threads.append(t)
|
||||||
self.failUnlessEqual(t.get_ident(), None)
|
self.failUnlessEqual(t.ident, None)
|
||||||
self.assert_(re.match('<TestThread\(.*, initial\)>', repr(t)))
|
self.assert_(re.match('<TestThread\(.*, initial\)>', repr(t)))
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ class ThreadTests(unittest.TestCase):
|
||||||
for t in threads:
|
for t in threads:
|
||||||
t.join(NUMTASKS)
|
t.join(NUMTASKS)
|
||||||
self.assert_(not t.is_alive())
|
self.assert_(not t.is_alive())
|
||||||
self.failIfEqual(t.get_ident(), 0)
|
self.failIfEqual(t.ident, 0)
|
||||||
self.assert_(re.match('<TestThread\(.*, \w+ -?\d+\)>', repr(t)))
|
self.assert_(re.match('<TestThread\(.*, \w+ -?\d+\)>', repr(t)))
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'all tasks done'
|
print 'all tasks done'
|
||||||
|
|
|
@ -663,7 +663,8 @@ class Thread(_Verbose):
|
||||||
|
|
||||||
setName = _old_api(set_name, "setName")
|
setName = _old_api(set_name, "setName")
|
||||||
|
|
||||||
def get_ident(self):
|
@property
|
||||||
|
def ident(self):
|
||||||
assert self.__initialized, "Thread.__init__() not called"
|
assert self.__initialized, "Thread.__init__() not called"
|
||||||
return self.__ident
|
return self.__ident
|
||||||
|
|
||||||
|
|
|
@ -422,7 +422,7 @@ Extension Modules
|
||||||
|
|
||||||
- Issue #2870: cmathmodule.c compile error.
|
- Issue #2870: cmathmodule.c compile error.
|
||||||
|
|
||||||
- Added a threading.Thread.getIdent() method.
|
- Added a threading.Thread.ident property.
|
||||||
|
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue