This document is for Celery's development version, which can be significantly different from previous releases. Get old docs here: 2.5.

celery.utils.functional

celery.utils.functional

Utilities for functions.

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

BSD, see LICENSE for more details.

class celery.utils.functional.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.
incr(key, delta=1)
items()
iteritems()
itervalues()
keys()
values()
celery.utils.functional.chunks(it, n)

Split an iterator into chunks with n elements each.

Examples

# n == 2 >>> x = chunks(iter([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 2) >>> list(x) [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10]]

# n == 3 >>> x = chunks(iter([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 3) >>> list(x) [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10]]

celery.utils.functional.first(predicate, iterable)

Returns the first element in iterable that predicate returns a True value for.

celery.utils.functional.firstmethod(method)

Returns a function that with a list of instances, finds the first instance that returns a value for the given method.

The list can also contain promises (promise.)

celery.utils.functional.is_list(l)
celery.utils.functional.mattrgetter(*attrs)

Like operator.itemgetter() but returns None on missing attributes instead of raising AttributeError.

celery.utils.functional.maybe_list(l)
celery.utils.functional.memoize(maxsize=None, Cache=<class celery.utils.functional.LRUCache at 0x10199c0b8>)
class celery.utils.functional.mpromise(fun, *args, **kwargs)

Memoized promise.

The function is only evaluated once, every subsequent access will return the same value.

evaluated

Set to to True after the promise has been evaluated.

evaluate()
evaluated = False
celery.utils.functional.noop(*args, **kwargs)

No operation.

Takes any arguments/keyword arguments and does nothing.

celery.utils.functional.padlist(container, size, default=None)

Pad list with default elements.

Examples:

>>> first, last, city = padlist(["George", "Costanza", "NYC"], 3)
("George", "Costanza", "NYC")
>>> first, last, city = padlist(["George", "Costanza"], 3)
("George", "Costanza", None)
>>> first, last, city, planet = padlist(["George", "Costanza",
                                         "NYC"], 4, default="Earth")
("George", "Costanza", "NYC", "Earth")
celery.utils.functional.regen(it)
celery.utils.functional.uniq(it)

Previous topic

celery.utils

Next topic

celery.utils.term

This Page