Asynchronous function calls

class gruvi.Future

The result of an asynchronous function call.

done()

Return whether this future is done.

result()

The result of the async function, if available.

exception()

The exception that was raised by the async function, if available.

set_result(result)

Mark the future as done and set its result.

set_exception(exception)

Mark the future as done and set an exception.

class gruvi.PoolBase(maxsize=None, single_shot=False, name=None)

Base class for the thread and fiber pools.

submit(func, *args)

Submit function func to the pool, which will run it asynchronously.

The function is called with positional argument args.

map(func, *iterables, **kwargs)

Apply func to the elements of the sequences in iterables.

If multiple iterables are provided, then func must take this many arguments, and is applied with one element from each iterable. All iterables must yield the same number of elements.

An optional timeout keyword argument may be provided to specify a timeout.

This returns a generator yielding the results.

This method is a switchpoint.

join()

Wait until all jobs in the pool have completed.

This method is a switchpoint.

close()

Close the pool.

New submissions will be blocked. Once all current jobs have finished, the workers will be stopped, and this method will return.

This method is a switchpoint.

class gruvi.FiberPool(maxsize=None, single_shot=False, name=None)

Bases: gruvi.PoolBase

Execute functions asynchronously in a pool of fibers.

class gruvi.ThreadPool(maxsize=None, single_shot=False, name=None)

Bases: gruvi.PoolBase

Execute functions asynchronously in a pool of threads.

gruvi.get_io_pool()

Return the thread pool for IO tasks.

By default there is one IO thread pool that is shared with all threads.

gruvi.get_cpu_pool()

Return the thread pool for CPU intenstive tasks.

By default there is one CPU thread pool that is shared with all threads.

gruvi.blocking(func, *args, **kwargs)

Run a function that uses blocking IO.

The function is run in the IO thread pool.

Previous topic

Synchronization primitives

Next topic

Addresses