Ver código fonte

:envvar:`C_STRICT_APP` now outputs traceback to stderr if something falls back to current_app

Ask Solem 12 anos atrás
pai
commit
978db4c8d8
1 arquivos alterados com 12 adições e 1 exclusões
  1. 12 1
      celery/_state.py

+ 12 - 1
celery/_state.py

@@ -12,6 +12,7 @@
 from __future__ import absolute_import
 
 import os
+import sys
 import threading
 import weakref
 
@@ -40,7 +41,7 @@ def set_default_app(app):
     default_app = app
 
 
-def get_current_app():
+def _get_current_app():
     if default_app is None:
         #: creates the global fallback app instance.
         from celery.app import Celery
@@ -51,6 +52,16 @@ def get_current_app():
         ))
     return _tls.current_app or default_app
 
+C_STRICT_APP = os.environ.get('C_STRICT_APP')
+if os.environ.get('C_STRICT_APP'):
+    def get_current_app():
+        import traceback
+        sys.stderr.write('USES CURRENT_APP\n')
+        traceback.print_stack(file=sys.stderr)
+        return _get_current_app()
+else:
+    get_current_app = _get_current_app
+
 
 def get_current_task():
     """Currently executing task."""