2323# with the multiprocessing module, which doesn't provide the old
2424# Java inspired names.
2525
26- __all__ = ['get_ident' , 'active_count ' , 'Condition ' , 'current_thread ' ,
27- 'enumerate' , 'main_thread' , 'TIMEOUT_MAX' ,
26+ __all__ = ['get_ident' , 'get_native_id ' , 'active_count ' , 'Condition ' ,
27+ 'current_thread' , ' enumerate' , 'main_thread' , 'TIMEOUT_MAX' ,
2828 'Event' , 'Lock' , 'RLock' , 'Semaphore' , 'BoundedSemaphore' , 'Thread' ,
2929 'Barrier' , 'BrokenBarrierError' , 'Timer' , 'ThreadError' ,
3030 'setprofile' , 'settrace' , 'local' , 'stack_size' ]
3434_allocate_lock = _thread .allocate_lock
3535_set_sentinel = _thread ._set_sentinel
3636get_ident = _thread .get_ident
37+ get_native_id = _thread .get_native_id
3738ThreadError = _thread .error
3839try :
3940 _CRLock = _thread .RLock
@@ -790,6 +791,7 @@ class is implemented.
790791 else :
791792 self ._daemonic = current_thread ().daemon
792793 self ._ident = None
794+ self ._native_id = 0
793795 self ._tstate_lock = None
794796 self ._started = Event ()
795797 self ._is_stopped = False
@@ -891,6 +893,9 @@ def _bootstrap(self):
891893 def _set_ident (self ):
892894 self ._ident = get_ident ()
893895
896+ def _set_native_id (self ):
897+ self ._native_id = get_native_id ()
898+
894899 def _set_tstate_lock (self ):
895900 """
896901 Set a lock object which will be released by the interpreter when
@@ -903,6 +908,7 @@ def _bootstrap_inner(self):
903908 try :
904909 self ._set_ident ()
905910 self ._set_tstate_lock ()
911+ self ._set_native_id ()
906912 self ._started .set ()
907913 with _active_limbo_lock :
908914 _active [self ._ident ] = self
@@ -1077,6 +1083,17 @@ def ident(self):
10771083 assert self ._initialized , "Thread.__init__() not called"
10781084 return self ._ident
10791085
1086+ @property
1087+ def native_id (self ):
1088+ """Native integral thread ID of this thread or 0 if it has not been started.
1089+
1090+ This is a non-negative integer. See the get_native_id() function.
1091+ This represents the Thread ID as reported by the kernel.
1092+
1093+ """
1094+ assert self ._initialized , "Thread.__init__() not called"
1095+ return self ._native_id
1096+
10801097 def is_alive (self ):
10811098 """Return whether the thread is alive.
10821099
@@ -1176,6 +1193,7 @@ def __init__(self):
11761193 self ._set_tstate_lock ()
11771194 self ._started .set ()
11781195 self ._set_ident ()
1196+ self ._set_native_id ()
11791197 with _active_limbo_lock :
11801198 _active [self ._ident ] = self
11811199
@@ -1195,6 +1213,7 @@ def __init__(self):
11951213
11961214 self ._started .set ()
11971215 self ._set_ident ()
1216+ self ._set_native_id ()
11981217 with _active_limbo_lock :
11991218 _active [self ._ident ] = self
12001219
0 commit comments