Преглед на файлове

Set current_task on Task.__call__

Ask Solem преди 13 години
родител
ревизия
20e97766b1
променени са 3 файла, в които са добавени 10 реда и са изтрити 4 реда
  1. 6 2
      celery/app/task.py
  2. 4 1
      celery/local.py
  3. 0 1
      setup.py

+ 6 - 2
celery/app/task.py

@@ -21,7 +21,7 @@ from kombu.utils import cached_property
 from celery import current_app
 from celery import states
 from celery.__compat__ import class_property
-from celery.state import get_current_task
+from celery.state import get_current_task, _task_stack
 from celery.datastructures import ExceptionInfo
 from celery.exceptions import MaxRetriesExceededError, RetryTaskError
 from celery.result import EagerResult
@@ -369,7 +369,11 @@ class BaseTask(object):
         setattr(self, attr, meth)
 
     def __call__(self, *args, **kwargs):
-        return self.run(*args, **kwargs)
+        _task_stack.push(self)
+        try:
+            return self.run(*args, **kwargs)
+        finally:
+            _task_stack.pop()
 
     # - tasks are pickled into the name of the task only, and the reciever
     # - simply grabs it from the local registry.

+ 4 - 1
celery/local.py

@@ -24,7 +24,10 @@ except ImportError:  # pragma: no cover
     try:
         from thread import get_ident  # noqa
     except ImportError:  # pragma: no cover
-        from dummy_thread import get_ident  # noqa
+        try:
+            from dummy_thread import get_ident  # noqa
+        except ImportError:  # pragma: no cover
+            from _thread import get_ident  # noqa
 
 
 def try_import(module, default=None):

+ 0 - 1
setup.py

@@ -144,7 +144,6 @@ install_requires = reqs("default-py3k.txt" if is_py3k else "default.txt")
 
 if is_jython:
     install_requires.extend(reqs("jython.txt"))
-
 if py_version[0:2] == (2, 6):
     install_requires.extend(reqs("py26.txt"))
 elif py_version[0:2] == (2, 5):