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.

__init__.py 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # -*- coding: utf-8 -*-
  2. """Distributed Task Queue"""
  3. # :copyright: (c) 2015 Ask Solem and individual contributors.
  4. # All rights # reserved.
  5. # :copyright: (c) 2012-2014 GoPivotal, Inc., All rights reserved.
  6. # :copyright: (c) 2009 - 2012 Ask Solem and individual contributors,
  7. # All rights reserved.
  8. # :license: BSD (3 Clause), see LICENSE for more details.
  9. from __future__ import absolute_import
  10. import os
  11. import sys
  12. from collections import namedtuple
  13. version_info_t = namedtuple(
  14. 'version_info_t', ('major', 'minor', 'micro', 'releaselevel', 'serial'),
  15. )
  16. SERIES = 'Cipater'
  17. VERSION = version_info_t(3, 1, 26, '.post2', '')
  18. __version__ = '{0.major}.{0.minor}.{0.micro}{0.releaselevel}'.format(VERSION)
  19. __author__ = 'Ask Solem'
  20. __contact__ = 'ask@celeryproject.org'
  21. __homepage__ = 'http://celeryproject.org'
  22. __docformat__ = 'restructuredtext'
  23. __all__ = [
  24. 'Celery', 'bugreport', 'shared_task', 'task',
  25. 'current_app', 'current_task', 'maybe_signature',
  26. 'chain', 'chord', 'chunks', 'group', 'signature',
  27. 'xmap', 'xstarmap', 'uuid', 'version', '__version__',
  28. ]
  29. VERSION_BANNER = '{0} ({1})'.format(__version__, SERIES)
  30. # -eof meta-
  31. if os.environ.get('C_IMPDEBUG'): # pragma: no cover
  32. from .five import builtins
  33. real_import = builtins.__import__
  34. def debug_import(name, locals=None, globals=None,
  35. fromlist=None, level=-1):
  36. glob = globals or getattr(sys, 'emarfteg_'[::-1])(1).f_globals
  37. importer_name = glob and glob.get('__name__') or 'unknown'
  38. print('-- {0} imports {1}'.format(importer_name, name))
  39. return real_import(name, locals, globals, fromlist, level)
  40. builtins.__import__ = debug_import
  41. # This is never executed, but tricks static analyzers (PyDev, PyCharm,
  42. # pylint, etc.) into knowing the types of these symbols, and what
  43. # they contain.
  44. STATICA_HACK = True
  45. globals()['kcah_acitats'[::-1].upper()] = False
  46. if STATICA_HACK: # pragma: no cover
  47. from celery.app import shared_task # noqa
  48. from celery.app.base import Celery # noqa
  49. from celery.app.utils import bugreport # noqa
  50. from celery.app.task import Task # noqa
  51. from celery._state import current_app, current_task # noqa
  52. from celery.canvas import ( # noqa
  53. chain, chord, chunks, group,
  54. signature, maybe_signature, xmap, xstarmap, subtask,
  55. )
  56. from celery.utils import uuid # noqa
  57. # Eventlet/gevent patching must happen before importing
  58. # anything else, so these tools must be at top-level.
  59. def _find_option_with_arg(argv, short_opts=None, long_opts=None):
  60. """Search argv for option specifying its short and longopt
  61. alternatives.
  62. Return the value of the option if found.
  63. """
  64. for i, arg in enumerate(argv):
  65. if arg.startswith('-'):
  66. if long_opts and arg.startswith('--'):
  67. name, _, val = arg.partition('=')
  68. if name in long_opts:
  69. return val
  70. if short_opts and arg in short_opts:
  71. return argv[i + 1]
  72. raise KeyError('|'.join(short_opts or [] + long_opts or []))
  73. def _patch_eventlet():
  74. import eventlet
  75. import eventlet.debug
  76. eventlet.monkey_patch()
  77. EVENTLET_DBLOCK = int(os.environ.get('EVENTLET_NOBLOCK', 0))
  78. if EVENTLET_DBLOCK:
  79. eventlet.debug.hub_blocking_detection(EVENTLET_DBLOCK)
  80. def _patch_gevent():
  81. from gevent import monkey, version_info
  82. monkey.patch_all()
  83. if version_info[0] == 0: # pragma: no cover
  84. # Signals aren't working in gevent versions <1.0,
  85. # and are not monkey patched by patch_all()
  86. from gevent import signal as _gevent_signal
  87. _signal = __import__('signal')
  88. _signal.signal = _gevent_signal
  89. def maybe_patch_concurrency(argv=sys.argv,
  90. short_opts=['-P'], long_opts=['--pool'],
  91. patches={'eventlet': _patch_eventlet,
  92. 'gevent': _patch_gevent}):
  93. """With short and long opt alternatives that specify the command line
  94. option to set the pool, this makes sure that anything that needs
  95. to be patched is completed as early as possible.
  96. (e.g. eventlet/gevent monkey patches)."""
  97. try:
  98. pool = _find_option_with_arg(argv, short_opts, long_opts)
  99. except KeyError:
  100. pass
  101. else:
  102. try:
  103. patcher = patches[pool]
  104. except KeyError:
  105. pass
  106. else:
  107. patcher()
  108. # set up eventlet/gevent environments ASAP.
  109. from celery import concurrency
  110. concurrency.get_implementation(pool)
  111. # Lazy loading
  112. from celery import five # noqa
  113. old_module, new_module = five.recreate_module( # pragma: no cover
  114. __name__,
  115. by_module={
  116. 'celery.app': ['Celery', 'bugreport', 'shared_task'],
  117. 'celery.app.task': ['Task'],
  118. 'celery._state': ['current_app', 'current_task'],
  119. 'celery.canvas': ['chain', 'chord', 'chunks', 'group',
  120. 'signature', 'maybe_signature', 'subtask',
  121. 'xmap', 'xstarmap'],
  122. 'celery.utils': ['uuid'],
  123. },
  124. direct={'task': 'celery.task'},
  125. __package__='celery', __file__=__file__,
  126. __path__=__path__, __doc__=__doc__, __version__=__version__,
  127. __author__=__author__, __contact__=__contact__,
  128. __homepage__=__homepage__, __docformat__=__docformat__, five=five,
  129. VERSION=VERSION, SERIES=SERIES, VERSION_BANNER=VERSION_BANNER,
  130. version_info_t=version_info_t,
  131. maybe_patch_concurrency=maybe_patch_concurrency,
  132. _find_option_with_arg=_find_option_with_arg,
  133. )