Back to index

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

Classes

class  error
class  LockType

Functions

def start_new_thread
def exit
def get_ident
def allocate_lock
def stack_size
def interrupt_main

Variables

list __all__
int TIMEOUT_MAX = 2
 _interrupt = False
 _main = True

Detailed Description

Drop-in replacement for the thread module.

Meant to be used as a brain-dead substitute so that threaded code does
not need to be rewritten for when the thread module is not present.

Suggested usage is::

    try:
import _thread
    except ImportError:
import _dummy_thread as _thread

Function Documentation

Dummy implementation of _thread.allocate_lock().

Definition at line 78 of file _dummy_thread.py.

00078 
00079 def allocate_lock():
00080     """Dummy implementation of _thread.allocate_lock()."""
00081     return LockType()

Dummy implementation of _thread.exit().

Definition at line 65 of file _dummy_thread.py.

00065 
00066 def exit():
00067     """Dummy implementation of _thread.exit()."""
00068     raise SystemExit

Dummy implementation of _thread.get_ident().

Since this module should only be used when _threadmodule is not
available, it is safe to assume that the current process is the
only thread.  Thus a constant can be safely returned.

Definition at line 69 of file _dummy_thread.py.

00069 
00070 def get_ident():
00071     """Dummy implementation of _thread.get_ident().
00072 
00073     Since this module should only be used when _threadmodule is not
00074     available, it is safe to assume that the current process is the
00075     only thread.  Thus a constant can be safely returned.
00076     """
00077     return -1

Here is the caller graph for this function:

Set _interrupt flag to True to have start_new_thread raise
KeyboardInterrupt upon exiting.

Definition at line 148 of file _dummy_thread.py.

00148 
00149 def interrupt_main():
00150     """Set _interrupt flag to True to have start_new_thread raise
00151     KeyboardInterrupt upon exiting."""
00152     if _main:
00153         raise KeyboardInterrupt
00154     else:
00155         global _interrupt
00156         _interrupt = True
def _dummy_thread.stack_size (   size = None)
Dummy implementation of _thread.stack_size().

Definition at line 82 of file _dummy_thread.py.

00082 
00083 def stack_size(size=None):
00084     """Dummy implementation of _thread.stack_size()."""
00085     if size is not None:
00086         raise error("setting thread stack size not supported")
00087     return 0

def _dummy_thread.start_new_thread (   function,
  args,
  kwargs = {} 
)
Dummy implementation of _thread.start_new_thread().

Compatibility is maintained by making sure that ``args`` is a
tuple and ``kwargs`` is a dictionary.  If an exception is raised
and it is SystemExit (which can be done by _thread.exit()) it is
caught and nothing is done; all other exceptions are printed out
by using traceback.print_exc().

If the executed function calls interrupt_main the KeyboardInterrupt will be
raised when the function returns.

Definition at line 33 of file _dummy_thread.py.

00033 
00034 def start_new_thread(function, args, kwargs={}):
00035     """Dummy implementation of _thread.start_new_thread().
00036 
00037     Compatibility is maintained by making sure that ``args`` is a
00038     tuple and ``kwargs`` is a dictionary.  If an exception is raised
00039     and it is SystemExit (which can be done by _thread.exit()) it is
00040     caught and nothing is done; all other exceptions are printed out
00041     by using traceback.print_exc().
00042 
00043     If the executed function calls interrupt_main the KeyboardInterrupt will be
00044     raised when the function returns.
00045 
00046     """
00047     if type(args) != type(tuple()):
00048         raise TypeError("2nd arg must be a tuple")
00049     if type(kwargs) != type(dict()):
00050         raise TypeError("3rd arg must be a dict")
00051     global _main
00052     _main = False
00053     try:
00054         function(*args, **kwargs)
00055     except SystemExit:
00056         pass
00057     except:
00058         import traceback
00059         traceback.print_exc()
00060     _main = True
00061     global _interrupt
00062     if _interrupt:
00063         _interrupt = False
00064         raise KeyboardInterrupt

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 ['error', 'start_new_thread', 'exit', 'get_ident', 'allocate_lock',
00002            'interrupt_main', 'LockType']

Definition at line 16 of file _dummy_thread.py.

Definition at line 144 of file _dummy_thread.py.

Definition at line 146 of file _dummy_thread.py.

Definition at line 20 of file _dummy_thread.py.