cooperative Package

cooperative Package

class cooperative.ValueBucket

Bases: object

Produces a callable that accumulates all non-None values it is called with in order.

The contents may be accessed or collected and drained, to make room for new content.

contents()
Returns:contents
drain_contents()

Starts a new collection to accumulate future contents and returns all of existing contents.

cooperative.accumulate(a_generator, cooperator=None)

Start a Deferred whose callBack arg is a deque of the accumulation of the values yielded from a_generator.

Parameters:a_generator – An iterator which yields some not None values.
Returns:A Deferred to which the next callback will be called with the yielded contents of the generator function.
cooperative.accumulation_handler(stopped_generator, spigot)

Drain the contents of the bucket from the spigot.

Parameters:
  • stopped_generator – Generator which as stopped
  • spigot – a Bucket.
Returns:

The contents of the bucket.

cooperative.batch_accumulate(max_batch_size, a_generator, cooperator=None)

Start a Deferred whose callBack arg is a deque of the accumulation of the values yielded from a_generator which is iterated over in batches the size of max_batch_size.

It should be more efficient to iterate over the generator in
batches and still provide enough speed for non-blocking execution.
Parameters:
  • max_batch_size – The number of iterations of the generator to consume at a time.
  • a_generator – An iterator which yields some not None values.
Returns:

A Deferred to which the next callback will be called with the yielded contents of the generator function.

_meta Module