Back to index

python3.2  3.2.2
Classes | Functions | Variables
threading Namespace Reference

Classes

class  _Verbose
class  _RLock
class  _Condition
class  _Semaphore
class  _BoundedSemaphore
class  _Event
class  Barrier
class  BrokenBarrierError
class  Thread
class  _Timer
class  _MainThread
class  _DummyThread

Functions

def setprofile
def settrace
def RLock
def Condition
def Semaphore
def BoundedSemaphore
def Event
def _newname
def Timer
def _pickSomeNonDaemonThread
def current_thread
def active_count
def _enumerate
def enumerate
def _after_fork

Variables

list __all__
 _start_new_thread = _thread.start_new_thread
 _allocate_lock = _thread.allocate_lock
 _get_ident = _thread.get_ident
 ThreadError = _thread.error
 _CRLock = _thread.RLock
 TIMEOUT_MAX = _thread.TIMEOUT_MAX
 _VERBOSE = False
 _profile_hook = None
 _trace_hook = None
 Lock = _allocate_lock
 _PyRLock = _RLock
int _counter = 0
tuple _active_limbo_lock = _allocate_lock()
dictionary _active = {}
dictionary _limbo = {}
tuple _dangling = WeakSet()
 currentThread = current_thread
 activeCount = active_count
tuple _shutdown = _MainThread()

Detailed Description

Thread module emulating a subset of Java's threading model.

Class Documentation

class threading::BrokenBarrierError

Definition at line 595 of file threading.py.


Function Documentation

def threading._after_fork ( ) [private]

Definition at line 1056 of file threading.py.

01056 
01057 def _after_fork():
01058     # This function is called by Python/ceval.c:PyEval_ReInitThreads which
01059     # is called from PyOS_AfterFork.  Here we cleanup threading module state
01060     # that should not exist after a fork.
01061 
01062     # Reset _active_limbo_lock, in case we forked while the lock was held
01063     # by another (non-forked) thread.  http://bugs.python.org/issue874900
01064     global _active_limbo_lock
01065     _active_limbo_lock = _allocate_lock()
01066 
01067     # fork() only copied the current thread; clear references to others.
01068     new_active = {}
01069     current = current_thread()
01070     with _active_limbo_lock:
01071         for thread in _active.values():
01072             if thread is current:
01073                 # There is only one active thread. We reset the ident to
01074                 # its new value since it can have changed.
01075                 ident = _get_ident()
01076                 thread._ident = ident
01077                 # Any condition variables hanging off of the active thread may
01078                 # be in an invalid state, so we reinitialize them.
01079                 thread._reset_internal_locks()
01080                 new_active[ident] = thread
01081             else:
01082                 # All the others are already stopped.
01083                 # We don't call _Thread__stop() because it tries to acquire
01084                 # thread._Thread__block which could also have been held while
01085                 # we forked.
01086                 thread._stopped = True
01087 
01088         _limbo.clear()
01089         _active.clear()
01090         _active.update(new_active)
01091         assert len(_active) == 1

Here is the call graph for this function:

def threading._enumerate ( ) [private]

Definition at line 1031 of file threading.py.

01031 
01032 def _enumerate():
01033     # Same as enumerate(), but without the lock. Internal use only.
01034     return list(_active.values()) + list(_limbo.values())

def threading._newname (   template = "Thread-%d") [private]

Definition at line 600 of file threading.py.

00600 
00601 def _newname(template="Thread-%d"):
00602     global _counter
00603     _counter = _counter + 1
00604     return template % _counter
00605 
# Active thread administration

Here is the caller graph for this function:

Definition at line 977 of file threading.py.

00977 
00978 def _pickSomeNonDaemonThread():
00979     for t in enumerate():
00980         if not t.daemon and t.is_alive():
00981             return t
00982     return None
00983 
00984 
00985 # Dummy thread class to represent threads not started here.
00986 # These aren't garbage collected when they die, nor can they be waited for.
00987 # If they invoke anything in threading.py that calls current_thread(), they
00988 # leave an entry in the _active dict forever after.
00989 # Their purpose is to return *something* from current_thread().
00990 # They are marked as daemon threads so we won't wait for them
00991 # when we exit (conform previous semantics).

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1025 of file threading.py.

01025 
01026 def active_count():
01027     with _active_limbo_lock:
01028         return len(_active) + len(_limbo)

def threading.BoundedSemaphore (   args,
  kwargs 
)

Definition at line 367 of file threading.py.

00367 
00368 def BoundedSemaphore(*args, **kwargs):
00369     return _BoundedSemaphore(*args, **kwargs)

Here is the caller graph for this function:

def threading.Condition (   args,
  kwargs 
)

Definition at line 173 of file threading.py.

00173 
00174 def Condition(*args, **kwargs):
00175     return _Condition(*args, **kwargs)

Here is the caller graph for this function:

Definition at line 1016 of file threading.py.

01016 
01017 def current_thread():
01018     try:
01019         return _active[_get_ident()]
01020     except KeyError:
01021         ##print "current_thread(): no current thread for", _get_ident()
01022         return _DummyThread()

Here is the caller graph for this function:

Definition at line 1035 of file threading.py.

01035 
01036 def enumerate():
01037     with _active_limbo_lock:
01038         return list(_active.values()) + list(_limbo.values())

def threading.Event (   args,
  kwargs 
)

Definition at line 382 of file threading.py.

00382 
00383 def Event(*args, **kwargs):
00384     return _Event(*args, **kwargs)

Here is the caller graph for this function:

def threading.RLock (   verbose = None,
  args,
  kwargs 
)

Definition at line 89 of file threading.py.

00089 
00090 def RLock(verbose=None, *args, **kwargs):
00091     if verbose is None:
00092         verbose = _VERBOSE
00093     if (__debug__ and verbose) or _CRLock is None:
00094         return _PyRLock(verbose, *args, **kwargs)
00095     return _CRLock(*args, **kwargs)

Here is the caller graph for this function:

def threading.Semaphore (   args,
  kwargs 
)

Definition at line 309 of file threading.py.

00309 
00310 def Semaphore(*args, **kwargs):
00311     return _Semaphore(*args, **kwargs)

Here is the caller graph for this function:

def threading.setprofile (   func)

Definition at line 77 of file threading.py.

00077 
00078 def setprofile(func):
00079     global _profile_hook
00080     _profile_hook = func

def threading.settrace (   func)

Definition at line 81 of file threading.py.

00081 
00082 def settrace(func):
00083     global _trace_hook
00084     _trace_hook = func
00085 
00086 # Synchronization classes

Here is the caller graph for this function:

def threading.Timer (   args,
  kwargs 
)

Definition at line 920 of file threading.py.

00920 
00921 def Timer(*args, **kwargs):
00922     return _Timer(*args, **kwargs)


Variable Documentation

Initial value:
00001 ['active_count', 'Condition', 'current_thread', 'enumerate', 'Event',
00002            'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Thread', 'Barrier',
00003            'Timer', 'setprofile', 'settrace', 'local', 'stack_size']

Definition at line 21 of file threading.py.

Definition at line 607 of file threading.py.

Definition at line 606 of file threading.py.

threading._allocate_lock = _thread.allocate_lock

Definition at line 27 of file threading.py.

Definition at line 599 of file threading.py.

threading._CRLock = _thread.RLock

Definition at line 31 of file threading.py.

Definition at line 611 of file threading.py.

threading._get_ident = _thread.get_ident

Definition at line 28 of file threading.py.

Definition at line 608 of file threading.py.

Definition at line 74 of file threading.py.

Definition at line 170 of file threading.py.

Definition at line 1045 of file threading.py.

threading._start_new_thread = _thread.start_new_thread

Definition at line 26 of file threading.py.

Definition at line 75 of file threading.py.

Definition at line 40 of file threading.py.

Definition at line 1029 of file threading.py.

Definition at line 1023 of file threading.py.

Definition at line 87 of file threading.py.

Definition at line 29 of file threading.py.

threading.TIMEOUT_MAX = _thread.TIMEOUT_MAX

Definition at line 34 of file threading.py.