Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

default.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. """
  3. celery.loaders.default
  4. ~~~~~~~~~~~~~~~~~~~~~~
  5. The default loader used when no custom app has been initialized.
  6. """
  7. from __future__ import absolute_import
  8. import os
  9. import warnings
  10. from celery.datastructures import DictAttribute
  11. from celery.exceptions import NotConfigured
  12. from celery.utils import strtobool
  13. from .base import BaseLoader
  14. __all__ = ['Loader', 'DEFAULT_CONFIG_MODULE']
  15. DEFAULT_CONFIG_MODULE = 'celeryconfig'
  16. #: Warns if configuration file is missing if :envvar:`C_WNOCONF` is set.
  17. C_WNOCONF = strtobool(os.environ.get('C_WNOCONF', False))
  18. class Loader(BaseLoader):
  19. """The loader used by the default app."""
  20. def setup_settings(self, settingsdict):
  21. return DictAttribute(settingsdict)
  22. def read_configuration(self, fail_silently=True):
  23. """Read configuration from :file:`celeryconfig.py` and configure
  24. celery and Django so it can be used by regular Python."""
  25. configname = os.environ.get('CELERY_CONFIG_MODULE',
  26. DEFAULT_CONFIG_MODULE)
  27. try:
  28. usercfg = self._import_config_module(configname)
  29. except ImportError:
  30. if not fail_silently:
  31. raise
  32. # billiard sets this if forked using execv
  33. if C_WNOCONF and not os.environ.get('FORKED_BY_MULTIPROCESSING'):
  34. warnings.warn(NotConfigured(
  35. 'No {module} module found! Please make sure it exists and '
  36. 'is available to Python.'.format(module=configname)))
  37. return self.setup_settings({})
  38. else:
  39. self.configured = True
  40. return self.setup_settings(usercfg)