celery.utils
¶
Utility functions.
Don’t import from here directly anymore, as these are only here for backwards compatibility.
- class celery.utils.cached_property(fget=None, fset=None, fdel=None)[исходный код]¶
Implementation of Cached property.
- deleter(fdel)[исходный код]¶
- setter(fset)[исходный код]¶
- celery.utils.chunks(it, n)[исходный код]¶
Split an iterator into chunks with n elements each.
Предупреждение
it
must be an actual iterator, if you pass this a concrete sequence will get you repeating elements.So
chunks(iter(range(1000)), 10)
is fine, butchunks(range(1000), 10)
is not.Пример
# 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.gen_task_name(app, name, module_name)[исходный код]¶
Generate task name from name/module pair.
- celery.utils.gen_unique_id(_uuid: ~typing.Callable[[], ~uuid.UUID] = <function uuid4>) str ¶
Generate unique id in UUID4 format.
- celery.utils.get_cls_by_name(name, aliases=None, imp=None, package=None, sep='.', default=None, **kwargs)¶
Get symbol by qualified name.
The name should be the full dot-separated path to the class:
modulename.ClassName
Example:
celery.concurrency.processes.TaskPool ^- class name
or using „:“ to separate module and symbol:
celery.concurrency.processes:TaskPool
If aliases is provided, a dict containing short name/long name mappings, the name is looked up in the aliases first.
Примеры
>>> symbol_by_name('celery.concurrency.processes.TaskPool') <class 'celery.concurrency.processes.TaskPool'>
>>> symbol_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 >>> symbol_by_name(TaskPool) is TaskPool True
- celery.utils.get_full_cls_name(obj)¶
Return object name.
- celery.utils.import_from_cwd(module, imp=None, package=None)[исходный код]¶
Import module, temporarily including modules in the current directory.
Modules located in the current directory has precedence over modules located in sys.path.
- celery.utils.instantiate(name, *args, **kwargs)[исходный код]¶
Instantiate class by name.
См.также
symbol_by_name()
.
- celery.utils.memoize(maxsize=None, keyfun=None, Cache=<class 'kombu.utils.functional.LRUCache'>)[исходный код]¶
Decorator to cache function return value.
- celery.utils.nodename(name, hostname)[исходный код]¶
Create node name from name/hostname pair.
- celery.utils.nodesplit(name)[исходный код]¶
Split node name into tuple of name/hostname.
- celery.utils.noop(*args, **kwargs)[исходный код]¶
No operation.
Takes any arguments/keyword arguments and does nothing.
- celery.utils.uuid(_uuid: ~typing.Callable[[], ~uuid.UUID] = <function uuid4>) str [исходный код]¶
Generate unique id in UUID4 format.
- celery.utils.worker_direct(hostname)[исходный код]¶
Return the
kombu.Queue
being a direct route to a worker.- Параметры:
hostname (str, Queue) – The fully qualified node name of a worker (e.g.,
w1@example.com
). If passed akombu.Queue
instance it will simply return that instead.