google.cloud.forseti.common.util.threadpool module

Thread pool implementation for async job distribution.

class Result[source]

Bases: object

Used to communicate job result values and exceptions.

get()[source]

Get value after worker has completed.

Returns:The value.
Return type:object
put(value, raised)[source]

Worker puts value or exception into result.

Parameters:
  • value (object) – A value or exception.
  • raised (bool) – Whether exception was raised.
class ThreadPool(num_workers)[source]

Bases: object

ThreadPool consumes tasks via queue.

add_func(func, *args, **kargs)[source]

Add a callable to the queue.

Parameters:
  • func (function) – A callable.
  • *args (list) – Non-keyworded variable args.
  • **kargs (dict) – Keyworded variable args.
Returns:

The result.

Return type:

Result

join()[source]

Returns after completion of all pending callables.

class Worker(queue)[source]

Bases: threading.Thread

Thread executing callables from queue.

run()[source]

Run the worker.