Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
concurrent.futures.thread.ThreadPoolExecutor Class Reference
Inheritance diagram for concurrent.futures.thread.ThreadPoolExecutor:
Inheritance graph
[legend]
Collaboration diagram for concurrent.futures.thread.ThreadPoolExecutor:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def submit
def shutdown
def map
def __enter__
def __exit__

Public Attributes

_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _adjust_thread_count

Private Attributes

 _max_workers
 _work_queue
 _threads
 _shutdown
 _shutdown_lock

Detailed Description

Definition at line 80 of file thread.py.


Constructor & Destructor Documentation

def concurrent.futures.thread.ThreadPoolExecutor.__init__ (   self,
  max_workers 
)
Initializes a new ThreadPoolExecutor instance.

Args:
    max_workers: The maximum number of threads that can be used to
execute the given calls.

Definition at line 81 of file thread.py.

00081 
00082     def __init__(self, max_workers):
00083         """Initializes a new ThreadPoolExecutor instance.
00084 
00085         Args:
00086             max_workers: The maximum number of threads that can be used to
00087                 execute the given calls.
00088         """
00089         self._max_workers = max_workers
00090         self._work_queue = queue.Queue()
00091         self._threads = set()
00092         self._shutdown = False
00093         self._shutdown_lock = threading.Lock()

Here is the caller graph for this function:


Member Function Documentation

def concurrent.futures._base.Executor.__enter__ (   self) [inherited]

Definition at line 562 of file _base.py.

00562 
00563     def __enter__(self):
00564         return self

def concurrent.futures._base.Executor.__exit__ (   self,
  exc_type,
  exc_val,
  exc_tb 
) [inherited]

Definition at line 565 of file _base.py.

00565 
00566     def __exit__(self, exc_type, exc_val, exc_tb):
00567         self.shutdown(wait=True)
00568         return False

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 107 of file thread.py.

00107 
00108     def _adjust_thread_count(self):
00109         # When the executor gets lost, the weakref callback will wake up
00110         # the worker threads.
00111         def weakref_cb(_, q=self._work_queue):
00112             q.put(None)
00113         # TODO(bquinlan): Should avoid creating new threads if there are more
00114         # idle threads than items in the work queue.
00115         if len(self._threads) < self._max_workers:
00116             t = threading.Thread(target=_worker,
00117                                  args=(weakref.ref(self, weakref_cb),
00118                                        self._work_queue))
00119             t.daemon = True
00120             t.start()
00121             self._threads.add(t)
00122             _threads_queues[t] = self._work_queue

Here is the caller graph for this function:

def concurrent.futures._base.Executor.map (   self,
  fn,
  iterables,
  timeout = None 
) [inherited]
Returns a iterator equivalent to map(fn, iter).

Args:
    fn: A callable that will take take as many arguments as there are
passed iterables.
    timeout: The maximum number of seconds to wait. If None, then there
is no limit on the wait time.

Returns:
    An iterator equivalent to: map(func, *iterables) but the calls may
    be evaluated out-of-order.

Raises:
    TimeoutError: If the entire result iterator could not be generated
before the given timeout.
    Exception: If fn(*args) raises for any values.

Definition at line 516 of file _base.py.

00516 
00517     def map(self, fn, *iterables, timeout=None):
00518         """Returns a iterator equivalent to map(fn, iter).
00519 
00520         Args:
00521             fn: A callable that will take take as many arguments as there are
00522                 passed iterables.
00523             timeout: The maximum number of seconds to wait. If None, then there
00524                 is no limit on the wait time.
00525 
00526         Returns:
00527             An iterator equivalent to: map(func, *iterables) but the calls may
00528             be evaluated out-of-order.
00529 
00530         Raises:
00531             TimeoutError: If the entire result iterator could not be generated
00532                 before the given timeout.
00533             Exception: If fn(*args) raises for any values.
00534         """
00535         if timeout is not None:
00536             end_time = timeout + time.time()
00537 
00538         fs = [self.submit(fn, *args) for args in zip(*iterables)]
00539 
00540         try:
00541             for future in fs:
00542                 if timeout is None:
00543                     yield future.result()
00544                 else:
00545                     yield future.result(end_time - time.time())
00546         finally:
00547             for future in fs:
00548                 future.cancel()

Here is the call graph for this function:

def concurrent.futures.thread.ThreadPoolExecutor.shutdown (   self,
  wait = True 
)
Clean-up the resources associated with the Executor.

It is safe to call this method several times. Otherwise, no other
methods can be called after this one.

Args:
    wait: If True then shutdown will not return until all running
futures have finished executing and the resources used by the
executor have been reclaimed.

Reimplemented from concurrent.futures._base.Executor.

Definition at line 123 of file thread.py.

00123 
00124     def shutdown(self, wait=True):
00125         with self._shutdown_lock:
00126             self._shutdown = True
00127             self._work_queue.put(None)
00128         if wait:
00129             for t in self._threads:
                t.join()
def concurrent.futures.thread.ThreadPoolExecutor.submit (   self,
  fn,
  args,
  kwargs 
)
Submits a callable to be executed with the given arguments.

Schedules the callable to be executed as fn(*args, **kwargs) and returns
a Future instance representing the execution of the callable.

Returns:
    A Future representing the given call.

Reimplemented from concurrent.futures._base.Executor.

Definition at line 94 of file thread.py.

00094 
00095     def submit(self, fn, *args, **kwargs):
00096         with self._shutdown_lock:
00097             if self._shutdown:
00098                 raise RuntimeError('cannot schedule new futures after shutdown')
00099 
00100             f = _base.Future()
00101             w = _WorkItem(f, fn, args, kwargs)
00102 
00103             self._work_queue.put(w)
00104             self._adjust_thread_count()
            return f

Here is the call graph for this function:


Member Data Documentation

Definition at line 88 of file thread.py.

Definition at line 91 of file thread.py.

Definition at line 92 of file thread.py.

Definition at line 90 of file thread.py.

Definition at line 89 of file thread.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.


The documentation for this class was generated from the following file: