This document describes Celery 2.4. For development docs, go here.

celery.datastructures

Custom types and 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)
items()
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

Exception instance.

tb = None

Pickleable traceback instance for use with traceback

traceback = None

String representation of the traceback.

type = None

Exception type.

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

expires
first

Get the oldest member.

maxlen
pop_value(value)

Remove membership by finding value.

update(other)

LRUCache

class celery.datastructures.LRUCache(limit=None)

LRU Cache implementation using a doubly linked list to track access.

Parameters:limit – The maximum number of keys to keep in the cache. When a new key is inserted and the limit has been exceeded, the Least Recently Used key will be discarded from the cache.
items()
iteritems()
itervalues()
keys()
values()