This document describes an older version of Celery (2.2). For the latest stable version please go here.

celery.datastructures

Custom data structures.

copyright:
  1. 2009 - 2011 by Ask Solem.
license:

BSD, see LICENSE for more details.

TokenBucket

class celery.datastructures.TokenBucket(fill_rate, capacity=1)

Token Bucket Algorithm.

See http://en.wikipedia.org/wiki/Token_Bucket Most of this code was stolen from an entry in the ASPN Python Cookbook: http://code.activestate.com/recipes/511490/

Thread safety

This implementation may not be thread safe.

can_consume(tokens=1)

Returns True if tokens number of tokens can be consumed from the bucket.

capacity = 1

Maximum number of tokensin the bucket.

expected_time(tokens=1)

Returns the expected time in seconds when a new token should be available.

Warning

This consumes a token from the bucket.

fill_rate = None

The rate in tokens/second that the bucket will be refilled

timestamp = None

Timestamp of the last time a token was taken out of the bucket.

AttributeDict

class celery.datastructures.AttributeDict

Dict subclass with attribute access.

class celery.datastructures.AttributeDictMixin

Adds attribute access to mappings.

d.key -> d[key]

DictAttribute

class celery.datastructures.DictAttribute(obj)

Dict interface to attributes.

obj[k] -> obj.k

get(key, default=None)
iteritems()
setdefault(key, default)

ConfigurationView

class celery.datastructures.ConfigurationView(changes, defaults)

A view over an applications configuration dicts.

If the key does not exist in changes, the defaults dict is consulted.

Parameters:
  • changes – Dict containing changes to the configuration.
  • defaults – Dict containing the default configuration.
changes = None
defaults = None
get(key, default=None)
items()
iteritems()
iterkeys()
itervalues()
keys()
setdefault(key, default)
update(*args, **kwargs)
values()

ExceptionInfo

class celery.datastructures.ExceptionInfo(exc_info)

Exception wrapping an exception and its traceback.

Parameters:exc_info – The exception info tuple as returned by sys.exc_info().
exception = None

The original exception.

traceback = None

A traceback form the point when exception was raised.

LimitedSet

class celery.datastructures.LimitedSet(maxlen=None, expires=None)

Kind-of Set with limitations.

Good for when you need to test for membership (a in set), but the list might become to big, so you want to limit it so it doesn’t consume too much resources.

Parameters:
  • maxlen – Maximum number of members before we start evicting expired members.
  • expires – Time in seconds, before a membership expires.
add(value)

Add a new member.

as_dict()
chronologically
clear()

Remove all members

first

Get the oldest member.

pop_value(value)

Remove membership by finding value.

update(other)

LocalCache

class celery.datastructures.LocalCache(limit=None)

Dictionary with a finite number of keys.

Older items expires first.

Functions

celery.datastructures.consume_queue(queue)

Iterator yielding all immediately available items in a Queue.Queue.

The iterator stops as soon as the queue raises Queue.Empty.

Examples

>>> q = Queue()
>>> map(q.put, range(4))
>>> list(consume_queue(q))
[0, 1, 2, 3]
>>> list(consume_queue(q))
[]

Previous topic

celery.execute.trace

Next topic

celery.routes

This Page