threading
index
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py
Module Docs

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

 
Modules
       
sys
warnings

 
Classes
       
__builtin__.object
thread._local
_Verbose(__builtin__.object)
Thread

 
class Thread(_Verbose)
    A class that represents a thread of control.
 
This class can be safely subclassed in a limited fashion.
 
 
Method resolution order:
Thread
_Verbose
__builtin__.object

Methods defined here:
__init__(self, group=None, target=None, name=None, args=(), kwargs=None, verbose=None)
This constructor should always be called with keyword arguments. Arguments are:
 
*group* should be None; reserved for future extension when a ThreadGroup
class is implemented.
 
*target* is the callable object to be invoked by the run()
method. Defaults to None, meaning nothing is called.
 
*name* is the thread name. By default, a unique name is constructed of
the form "Thread-N" where N is a small decimal number.
 
*args* is the argument tuple for the target invocation. Defaults to ().
 
*kwargs* is a dictionary of keyword arguments for the target
invocation. Defaults to {}.
 
If a subclass overrides the constructor, it must make sure to invoke
the base class constructor (Thread.__init__()) before doing anything
else to the thread.
__repr__(self)
getName(self)
isAlive(self)
Return whether the thread is alive.
 
This method returns True just before the run() method starts until just
after the run() method terminates. The module function enumerate()
returns a list of all alive threads.
isDaemon(self)
is_alive = isAlive(self)
join(self, timeout=None)
Wait until the thread terminates.
 
This blocks the calling thread until the thread whose join() method is
called terminates -- either normally or through an unhandled exception
or until the optional timeout occurs.
 
When the timeout argument is present and not None, it should be a
floating point number specifying a timeout for the operation in seconds
(or fractions thereof). As join() always returns None, you must call
isAlive() after join() to decide whether a timeout happened -- if the
thread is still alive, the join() call timed out.
 
When the timeout argument is not present or None, the operation will
block until the thread terminates.
 
A thread can be join()ed many times.
 
join() raises a RuntimeError if an attempt is made to join the current
thread as that would cause a deadlock. It is also an error to join() a
thread before it has been started and attempts to do so raises the same
exception.
run(self)
Method representing the thread's activity.
 
You may override this method in a subclass. The standard run() method
invokes the callable object passed to the object's constructor as the
target argument, if any, with sequential and keyword arguments taken
from the args and kwargs arguments, respectively.
setDaemon(self, daemonic)
setName(self, name)
start(self)
Start the thread's activity.
 
It must be called at most once per thread object. It arranges for the
object's run() method to be invoked in a separate thread of control.
 
This method will raise a RuntimeError if called more than once on the
same thread object.

Data descriptors defined here:
daemon
A boolean value indicating whether this thread is a daemon thread (True) or not (False).
 
This must be set before start() is called, otherwise RuntimeError is
raised. Its initial value is inherited from the creating thread; the
main thread is not a daemon thread and therefore all threads created in
the main thread default to daemon = False.
 
The entire Python program exits when no alive non-daemon threads are
left.
ident
Thread identifier of this thread or None if it has not been started.
 
This is a nonzero integer. See the thread.get_ident() function. Thread
identifiers may be recycled when a thread exits and another thread is
created. The identifier is available even after the thread has exited.
name
A string used for identification purposes only.
 
It has no semantics. Multiple threads may be given the same name. The
initial name is set by the constructor.

Data descriptors inherited from _Verbose:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
local = class _local(__builtin__.object)
    Thread-local data
 
  Methods defined here:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Data and other attributes defined here:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
Functions
       
BoundedSemaphore(*args, **kwargs)
A factory function that returns a new bounded semaphore.
 
A bounded semaphore checks to make sure its current value doesn't exceed its
initial value. If it does, ValueError is raised. In most situations
semaphores are used to guard resources with limited capacity.
 
If the semaphore is released too many times it's a sign of a bug. If not
given, value defaults to 1.
 
Like regular semaphores, bounded semaphores manage a counter representing
the number of release() calls minus the number of acquire() calls, plus an
initial value. The acquire() method blocks if necessary until it can return
without making the counter negative. If not given, value defaults to 1.
Condition(*args, **kwargs)
Factory function that returns a new condition variable object.
 
A condition variable allows one or more threads to wait until they are
notified by another thread.
 
If the lock argument is given and not None, it must be a Lock or RLock
object, and it is used as the underlying lock. Otherwise, a new RLock object
is created and used as the underlying lock.
Event(*args, **kwargs)
A factory function that returns a new event.
 
Events manage a flag that can be set to true with the set() method and reset
to false with the clear() method. The wait() method blocks until the flag is
true.
Lock = allocate_lock(...)
allocate_lock() -> lock object
(allocate() is an obsolete synonym)
 
Create a new lock object.  See help(LockType) for information about locks.
RLock(*args, **kwargs)
Factory function that returns a new reentrant lock.
 
A reentrant lock must be released by the thread that acquired it. Once a
thread has acquired a reentrant lock, the same thread may acquire it again
without blocking; the thread must release it once for each time it has
acquired it.
Semaphore(*args, **kwargs)
A factory function that returns a new semaphore.
 
Semaphores manage a counter representing the number of release() calls minus
the number of acquire() calls, plus an initial value. The acquire() method
blocks if necessary until it can return without making the counter
negative. If not given, value defaults to 1.
Timer(*args, **kwargs)
Factory function to create a Timer object.
 
Timers call a function after a specified number of seconds:
 
    t = Timer(30.0, f, args=[], kwargs={})
    t.start()
    t.cancel()     # stop the timer's action if it's still waiting
activeCount()
Return the number of Thread objects currently alive.
 
The returned count is equal to the length of the list returned by
enumerate().
active_count = activeCount()
Return the number of Thread objects currently alive.
 
The returned count is equal to the length of the list returned by
enumerate().
currentThread()
Return the current Thread object, corresponding to the caller's thread of control.
 
If the caller's thread of control was not created through the threading
module, a dummy thread object with limited functionality is returned.
current_thread = currentThread()
Return the current Thread object, corresponding to the caller's thread of control.
 
If the caller's thread of control was not created through the threading
module, a dummy thread object with limited functionality is returned.
enumerate()
Return a list of all Thread objects currently alive.
 
The list includes daemonic threads, dummy thread objects created by
current_thread(), and the main thread. It excludes terminated threads and
threads that have not yet been started.
setprofile(func)
Set a profile function for all threads started from the threading module.
 
The func will be passed to sys.setprofile() for each thread, before its
run() method is called.
settrace(func)
Set a trace function for all threads started from the threading module.
 
The func will be passed to sys.settrace() for each thread, before its run()
method is called.
stack_size(...)
stack_size([size]) -> size
 
Return the thread stack size used when creating new threads.  The
optional size argument specifies the stack size (in bytes) to be used
for subsequently created threads, and must be 0 (use platform or
configured default) or a positive integer value of at least 32,768 (32k).
If changing the thread stack size is unsupported, a ThreadError
exception is raised.  If the specified size is invalid, a ValueError
exception is raised, and the stack size is unmodified.  32k bytes
 currently the minimum supported stack size value to guarantee
sufficient stack space for the interpreter itself.
 
Note that some platforms may have particular restrictions on values for
the stack size, such as requiring a minimum stack size larger than 32kB or
requiring allocation in multiples of the system memory page size
- platform documentation should be referred to for more information
(4kB pages are common; using multiples of 4096 for the stack size is
the suggested approach in the absence of more specific information).

 
Data
        __all__ = ['activeCount', 'active_count', 'Condition', 'currentThread', 'current_thread', 'enumerate', 'Event', 'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Thread', 'Timer', 'setprofile', 'settrace', 'local', 'stack_size']