any given threading.Thread object. feature request issue 2871.
constructor.
+.. method:: Thread.getIdent()
+
+ Return the 'thread identifier' of this thread or None if the thread has not
+ been started. This is a nonzero integer. See the :mod:`thread` module's
+ :func:`get_ident()` function. Thread identifiers may be recycled when a
+ thread exits and another thread is created. The identifier is returned
+ even after the thread has exited.
+
+ .. versionadded:: 2.6
+
+
.. method:: Thread.isAlive()
Return whether the thread is alive.
import test.test_support
from test.test_support import verbose
import random
+import re
import sys
import threading
import thread
for i in range(NUMTASKS):
t = TestThread("<thread %d>"%i, self, sema, mutex, numrunning)
threads.append(t)
+ self.failUnlessEqual(t.getIdent(), None)
+ self.assert_(re.match('<TestThread\(.*, initial\)>', repr(t)))
t.start()
if verbose:
for t in threads:
t.join(NUMTASKS)
self.assert_(not t.isAlive())
+ self.failIfEqual(t.getIdent(), 0)
+ self.assert_(re.match('<TestThread\(.*, \w+ -?\d+\)>', repr(t)))
if verbose:
print 'all tasks done'
self.assertEqual(numrunning.get(), 0)
self.__args = args
self.__kwargs = kwargs
self.__daemonic = self._set_daemon()
+ self.__ident = None
self.__started = Event()
self.__stopped = False
self.__block = Condition(Lock())
if self.__stopped:
status = "stopped"
if self.__daemonic:
- status = status + " daemon"
+ status += " daemon"
+ if self.__ident is not None:
+ status += " %s" % self.__ident
return "<%s(%s, %s)>" % (self.__class__.__name__, self.__name, status)
def start(self):
def __bootstrap_inner(self):
try:
+ self.__ident = _get_ident()
self.__started.set()
_active_limbo_lock.acquire()
- _active[_get_ident()] = self
+ _active[self.__ident] = self
del _limbo[self]
_active_limbo_lock.release()
if __debug__:
assert self.__initialized, "Thread.__init__() not called"
self.__name = str(name)
+ def getIdent(self):
+ assert self.__initialized, "Thread.__init__() not called"
+ return self.__ident
+
def isAlive(self):
assert self.__initialized, "Thread.__init__() not called"
return self.__started.isSet() and not self.__stopped
- Issue #2870: cmathmodule.c compile error.
+- Added a threading.Thread.getIdent() method.
+
Library
-------