Permalink
Browse files

Moves celery.app.state -> celery.state so that app is loaded late

  • Loading branch information...
1 parent e2b052c commit b6834ebefcf887b58ca0d1da8ce57e026ed6cd61 @ask committed May 16, 2012
View
@@ -20,7 +20,7 @@
old_module, new_module = recreate_module(__name__, # pragma: no cover
by_module={
"celery.app": ["Celery", "bugreport"],
- "celery.app.state": ["current_app", "current_task"],
+ "celery.state": ["current_app", "current_task"],
"celery.canvas": ["chain", "chord", "chunks",
"group", "subtask", "xmap", "xstarmap"],
"celery.utils": ["uuid"],
@@ -14,13 +14,13 @@
import os
from celery.local import Proxy
-
-from . import state
-from .state import ( # noqa
+from celery import state
+from celery.state import ( # noqa
set_default_app,
get_current_app as current_app,
get_current_task as current_task,
)
+
from .base import Celery, AppPickler # noqa
#: Proxy always returning the app set as default.
View
@@ -27,14 +27,14 @@
from celery.exceptions import AlwaysEagerIgnored
from celery.loaders import get_loader_cls
from celery.local import PromiseProxy, maybe_evaluate
+from celery.state import _tls, get_current_app
from celery.utils.functional import first
from celery.utils.imports import instantiate, symbol_by_name
from .annotations import prepare as prepare_annotations
from .builtins import shared_task, load_shared_tasks
from .defaults import DEFAULTS, find_deprecated_settings
from .registry import TaskRegistry
-from .state import _tls, get_current_app
from .utils import AppPickler, Settings, bugreport, _unpickle_app
@@ -4,6 +4,7 @@
from itertools import starmap
+from celery.state import get_current_task
from celery.utils import uuid
#: global list of functions defining tasks that should be
@@ -105,7 +106,6 @@ def chunks(task, it, n):
def add_group_task(app):
_app = app
from celery.canvas import subtask
- from celery.app.state import get_current_task
from celery.result import from_serializable
class Group(app.Task):
View
@@ -7,6 +7,7 @@
from kombu.log import NullHandler
from celery import signals
+from celery.state import get_current_task
from celery.utils import isatty
from celery.utils.compat import WatchedFileHandler
from celery.utils.log import (
@@ -17,8 +18,6 @@
)
from celery.utils.term import colored
-from .state import get_current_task
-
is_py3k = sys.version_info[0] == 3
View
@@ -21,6 +21,7 @@
from celery import current_app
from celery import states
from celery.__compat__ import class_property
+from celery.state import get_current_task
from celery.datastructures import ExceptionInfo
from celery.exceptions import MaxRetriesExceededError, RetryTaskError
from celery.local import LocalStack
@@ -32,7 +33,6 @@
from celery.utils.mail import ErrorMail
from .annotations import resolve_all as resolve_all_annotations
-from .state import get_current_task
from .registry import _unpickle_task
#: extracts options related to publishing a message from a dict.
@@ -5,8 +5,8 @@
from kombu.utils.url import _parse_url
-from celery.app.state import current_app
from celery.local import Proxy
+from celery.state import current_app
from celery.utils.imports import symbol_by_name
from celery.utils.functional import memoize
@@ -12,6 +12,7 @@
"""
from __future__ import absolute_import
+from celery.state import current_app
from celery.utils import deprecated
from celery.utils.imports import symbol_by_name
@@ -28,12 +29,10 @@ def get_loader_cls(loader):
@deprecated(deprecation="2.5", removal="3.0",
alternative="celery.current_app.loader")
def current_loader():
- from celery.app.state import current_app
return current_app.loader
@deprecated(deprecation="2.5", removal="3.0",
alternative="celery.current_app.conf")
def load_settings():
- from celery.app.state import current_app
return current_app.conf
@@ -19,11 +19,15 @@ class _TLS(threading.local):
def set_default_app(app):
global default_app
- default_app = app
+ if default_app is None:
+ default_app = app
def get_current_app():
- return getattr(_tls, "current_app", None) or default_app
+ if default_app is None:
+ # creates the default app, but we want to defer that.
+ import celery.app # noqa
+ return _tls.current_app or default_app
def get_current_task():
@@ -11,7 +11,7 @@
"""
from __future__ import absolute_import
-from celery.app.state import current_app, current_task as current
+from celery.state import current_app, current_task as current
from celery.__compat__ import MagicModule, recreate_module
from celery.local import Proxy
View
@@ -2,8 +2,8 @@
from __future__ import absolute_import
from __future__ import with_statement
+from celery.state import get_current_task
from celery.app import app_or_default
-from celery.app.state import get_current_task
from celery.canvas import subtask, maybe_subtask # noqa
from celery.utils import uuid
from celery.utils.compat import UserList
@@ -28,7 +28,7 @@
from celery import current_app
from celery import states, signals
-from celery.app.state import _task_stack
+from celery.state import _task_stack
from celery.app.task import BaseTask, Context
from celery.datastructures import ExceptionInfo
from celery.exceptions import RetryTaskError
@@ -4,7 +4,7 @@
from celery import current_app as app, group, task, chord
from celery.app import builtins
-from celery.app.state import _task_stack
+from celery.state import _task_stack
from celery.tests.utils import Case
@@ -230,11 +230,11 @@ def test_task():
pass
test_task.logger.handlers = []
self.task = test_task
- from celery.app.state import _task_stack
+ from celery.state import _task_stack
_task_stack.push(test_task)
def tearDown(self):
- from celery.app.state import _task_stack
+ from celery.state import _task_stack
_task_stack.pop()
def setup_logger(self, *args, **kwargs):
@@ -148,7 +148,7 @@ def send(self, *args, **kwargs):
@current_app.task
def xyz():
pass
- from celery.app.state import _task_stack
+ from celery.state import _task_stack
_task_stack.push(xyz)
try:
ts.apply_async(publisher=Publisher())
@@ -803,7 +803,7 @@ def test_use_pidfile(self, create_pidlock):
def test_process_initializer(self, set_mp_process_title, _signals):
from celery import Celery
from celery import signals
- from celery.app.state import _tls
+ from celery.state import _tls
from celery.concurrency.processes import process_initializer
from celery.concurrency.processes import (WORKER_SIGRESET,
WORKER_SIGIGNORE)

0 comments on commit b6834eb

Please sign in to comment.