diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2008-06-01 23:48:47 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2008-06-01 23:48:47 (GMT) |
commit | 8856ddae2522c644132b5d0730ab60021f2ce13e (patch) | |
tree | 717f19f039e2319d93159ca0e602165bac7dbf44 /Lib/threading.py | |
parent | 1bd52d745b16c1a41dd63869264315a4d138f62f (diff) | |
download | cpython-8856ddae2522c644132b5d0730ab60021f2ce13e.zip cpython-8856ddae2522c644132b5d0730ab60021f2ce13e.tar.gz cpython-8856ddae2522c644132b5d0730ab60021f2ce13e.tar.bz2 |
Adds a Thread.getIdent() method to provide the _get_ident() value for
any given threading.Thread object. feature request issue 2871.
Diffstat (limited to 'Lib/threading.py')
-rw-r--r-- | Lib/threading.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/threading.py b/Lib/threading.py index d497a46..0d34b6a 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -414,6 +414,7 @@ class Thread(_Verbose): self.__args = args self.__kwargs = kwargs self.__daemonic = self._set_daemon() + self.__ident = None self.__started = Event() self.__stopped = False self.__block = Condition(Lock()) @@ -434,7 +435,9 @@ class Thread(_Verbose): 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): @@ -481,9 +484,10 @@ class Thread(_Verbose): 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__: @@ -635,6 +639,10 @@ class Thread(_Verbose): 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 |