This document describes an older version of Celery (2.1). For the latest stable version please go here.
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]]
Returns the first element in iterable that predicate returns a True value for.
Returns a functions 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.)
With a function, and a list of keyword arguments, returns arguments in the list which the function takes.
If the object has an argspec attribute that is used instead of using the inspect.getargspec`() introspection.
Parameters: |
|
---|
Examples
>>> def foo(self, x, y, logfile=None, loglevel=None):
... return x * y
>>> fun_takes_kwargs(foo, ["logfile", "loglevel", "task_id"])
["logfile", "loglevel"]
>>> def foo(self, x, y, **kwargs):
>>> fun_takes_kwargs(foo, ["logfile", "loglevel", "task_id"])
["logfile", "loglevel", "task_id"]
Generate a unique id, having - hopefully - a very small chance of collission.
For now this is provided by uuid.uuid4().
Get class by name.
The name should be the full dot-separated path to the class:
modulename.ClassName
Example:
celery.concurrency.processes.TaskPool
^- class name
If aliases is provided, a dict containing short name/long name mappings, the name is looked up in the aliases first.
Examples:
>>> get_cls_by_name("celery.concurrency.processes.TaskPool") <class 'celery.concurrency.processes.TaskPool'>>>> get_cls_by_name("default", { ... "default": "celery.concurrency.processes.TaskPool"}) <class 'celery.concurrency.processes.TaskPool'># Does not try to look up non-string names. >>> from celery.concurrency.processes import TaskPool >>> get_cls_by_name(TaskPool) is TaskPool True
With a class, get its full module and class name.
Instantiate class by name.
See get_cls_by_name().
Make sure keyword arguments are not in unicode.
Like operator.itemgetter() but returns None on missing attributes instead of raising AttributeError.
Either datetime | str -> datetime or None -> None
Evaluates if the value is a promise.
Like operator.itemgetter() but returns None on missing items instead of raising KeyError.
Memoized promise.
The function is only evaluated once, every subsequent access will return the same value.
Set to to True after the promise has been evaluated.
No operation.
Takes any arguments/keyword arguments and does nothing.
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")
A promise.
Evaluated when called or if the evaluate() method is called. The function is evaluated on every access, so the value is not memoized (see mpromise).
Iterate over all elements in the iterator, and when its exhausted yield the last value infinitely.
Retry the function over and over until max retries is exceeded.
For each retry we sleep a for a while before we try again, this interval is increased for every retry until the max seconds is reached.
Parameters: |
|
---|
Truncates text to a maximum number of characters.