Module thread
[hide private]
[frames] | no frames]

Module thread

This module provides primitive operations to write multi-threaded programs. The 'threading' module provides a more convenient interface.

Classes [hide private]
LockType
A lock object is a synchronization primitive.
_local
Thread-local data
error
Functions [hide private]
lock object
allocate()
(allocate() is an obsolete synonym)
lock object
allocate_lock()
(allocate() is an obsolete synonym)
 
exit()
(PyThread_exit_thread() is an obsolete synonym)
 
exit_thread()
(PyThread_exit_thread() is an obsolete synonym)
integer
get_ident()
Return a non-zero integer that uniquely identifies the current thread amongst other threads that exist simultaneously.
 
interrupt_main()
Raise a KeyboardInterrupt in the main thread.
size
stack_size(size=...)
Return the thread stack size used when creating new threads.
 
start_new(function, args, kwargs=...)
(start_new() is an obsolete synonym)
 
start_new_thread(function, args, kwargs=...)
(start_new() is an obsolete synonym)
Function Details [hide private]

allocate()

 

(allocate() is an obsolete synonym)

Create a new lock object. See LockType.__doc__ for information about locks.

Returns: lock object

allocate_lock()

 

(allocate() is an obsolete synonym)

Create a new lock object. See LockType.__doc__ for information about locks.

Returns: lock object

exit()

 

(PyThread_exit_thread() is an obsolete synonym)

This is synonymous to ``raise SystemExit''. It will cause the current thread to exit silently unless the exception is caught.

exit_thread()

 

(PyThread_exit_thread() is an obsolete synonym)

This is synonymous to ``raise SystemExit''. It will cause the current thread to exit silently unless the exception is caught.

get_ident()

 

Return a non-zero integer that uniquely identifies the current thread amongst other threads that exist simultaneously. This may be used to identify per-thread resources. Even though on some platforms threads identities may appear to be allocated consecutive numbers starting at 1, this behavior should not be relied upon, and the number should be seen purely as a magic cookie. A thread's identity may be reused for another thread after it exits.

Returns: integer

interrupt_main()

 

Raise a KeyboardInterrupt in the main thread. A subthread can use this function to interrupt the main thread.

stack_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).

Returns: size

start_new(function, args, kwargs=...)

 

(start_new() is an obsolete synonym)

Start a new thread and return its identifier. The thread will call the function with positional arguments from the tuple args and keyword arguments taken from the optional dictionary kwargs. The thread exits when the function returns; the return value is ignored. The thread will also exit when the function raises an unhandled exception; a stack trace will be printed unless the exception is SystemExit.

start_new_thread(function, args, kwargs=...)

 

(start_new() is an obsolete synonym)

Start a new thread and return its identifier. The thread will call the function with positional arguments from the tuple args and keyword arguments taken from the optional dictionary kwargs. The thread exits when the function returns; the return value is ignored. The thread will also exit when the function raises an unhandled exception; a stack trace will be printed unless the exception is SystemExit.