Table Of Contents

Previous topic

Unuk

Next topic

Http Client

This Page

Concurrency

Concurrency module which provides the same interface for threads and process.

Multiprocessing is available for Python 2.6 and above via the multiprocessing library. Adaped from the Python standard library and Celery.

To obtain an instance of unuk.concurrency.ConcurrentPool you can used the shortcut function

Concurrent Pool Class

class unuk.concurrency.ConcurrentPool(minworkers=None, maxworkers=None, logger=None, name=None, maxtasksperchild=None, timeout=None, soft_timeout=None, initializer=None, initargs=())

Base class for managing queue with several concurrent threads or processes.

workertype

type of worker, “process” or “thread”

exception SoftTimeLimitExceeded

The soft time limit has been exceeded. This exception is raised to give the task a chance to clean up.

ConcurrentPool.FinalizeHandler

alias of Finalize

ConcurrentPool.workerFactory

Factory class for worker processes.

ConcurrentPool.state

Pool state, one of NOT_STARTED=-1, RUN=0, CLOSE=1, TERMINATED=2.

ConcurrentPool.workers

Number of workers

ConcurrentPool.inqueue

Approximate size of task queue

ConcurrentPool.started

True is pool has started.

ConcurrentPool.joined

True is pool has joined.

ConcurrentPool.apply(func, args=(), kwds={})

Equivalent of apply() builtin

ConcurrentPool.start()

Start the pool. If the pool was already started an AlreadyStarted exception will be raised.

ConcurrentPool.adjustPoolsize(size)

Bring the number of pool processes up to the specified number, for use after reaping workers which have exited.

ConcurrentPool.apply_async(func, args=(), kwds={}, callback=None, accept_callback=None, timeout_callback=None, waitforslot=False, error_callback=None)

Asynchronous equivalent of apply() builtin. Call a callable object in a separate worker.

  • func: callable object to be called on a pool worker.
  • args: tuple of positional arguments to be passed to func.
  • kwds: dictionary of keyword arguments to be passed to func.
  • callback: functions called when the func return its value.
  • accept_callback: called when the job is accepted to be executed.
  • timeout_callback: called when the job has timeout.
  • error_callback: called when the job has failed.
ConcurrentPool.close()

Close the pool.