celery.utils

celery.utils

Utility functions.

celery.utils.worker_direct(hostname)[源代码]

Return kombu.Queue that is a direct route to a worker by hostname.

参数:hostname – The fully qualified node name of a worker (e.g. w1@example.com). If passed a kombu.Queue instance it will simply return that instead.

celery.utils.warn_deprecated(description=None, deprecation=None, removal=None, alternative=None, stacklevel=2)[源代码]

celery.utils.deprecated(deprecation=None, removal=None, alternative=None, description=None)[源代码]

Decorator for deprecated functions.

A deprecation warning will be emitted when the function is called.

参数:
  • deprecation – Version that marks first deprecation, if this argument is not set a PendingDeprecationWarning will be emitted instead.
  • removed – Future version when this feature will be removed.
  • alternative – Instructions for an alternative solution (if any).
  • description – Description of what is being deprecated.

celery.utils.lpmerge(L, R)[源代码]

In place left precedent dictionary merge.

Keeps values from L, if the value in R is None.

celery.utils.is_iterable(obj)[源代码]

celery.utils.isatty(fh)[源代码]

celery.utils.cry(out=None, sepchr=’=’, seplen=49)[源代码]

Return stacktrace of all active threads, taken from https://gist.github.com/737056.

celery.utils.maybe_reraise()[源代码]

Re-raise if an exception is currently being handled, or return otherwise.

celery.utils.strtobool(term, table={‘1’: True, ‘0’: False, ‘false’: False, ‘no’: False, ‘off’: False, ‘yes’: True, ‘on’: True, ‘true’: True})[源代码]

Convert common terms for true/false to bool (true/false/yes/no/on/off/1/0).

celery.utils.jsonify(obj, builtin_types=(<type ‘int’>, <type ‘float’>, <type ‘basestring’>), key=None, keyfilter=None, unknown_type_filter=None)[源代码]

Transforms object making it suitable for json serialization

celery.utils.gen_task_name(app, name, module_name)[源代码]

Generate task name from name/module pair.

celery.utils.nodename(name, hostname)

Create node name from name/hostname pair.

celery.utils.nodesplit(nodename)

Split node name into tuple of name/hostname.

class celery.utils.cached_property(fget=None, fset=None, fdel=None, doc=None)

Property descriptor that caches the return value of the get function.

Examples

  1. @cached_property
  2. def connection(self):
  3. return Connection()
  4. @connection.setter # Prepares stored value
  5. def connection(self, value):
  6. if value is None:
  7. raise TypeError('Connection must be a connection')
  8. return value
  9. @connection.deleter
  10. def connection(self, value):
  11. # Additional action to do at del(self.attr)
  12. if value is not None:
  13. print('Connection {0!r} deleted'.format(value)
  • deleter(fdel)

  • setter(fset)