我的设置包括 django 1.5.1、celery 3.1.0 和 redis 作为后端
$ python manage.py celerycam -b 'redis://localhost:6379/0'
使 celerycam 运行,但它不断吐出以下内容:
TransactionManagementError: This code isn't under transaction management
[2013-11-19 15:19:44,097: ERROR/MainProcess] Error in timer: TransactionManagementError("This code isn't under transaction management",)
Traceback (most recent call last):
File "/Users/andres/.virtualenvs/rpmwest/lib/python2.7/site-packages/kombu/async/timer.py", line 166, in apply_entry
entry()
File "/Users/andres/.virtualenvs/rpmwest/lib/python2.7/site-packages/kombu/async/timer.py", line 64, in __call__
return self.fun(*self.args, **self.kwargs)
File "/Users/andres/.virtualenvs/rpmwest/lib/python2.7/site-packages/kombu/async/timer.py", line 127, in _reschedules
return fun(*args, **kwargs)
File "/Users/andres/.virtualenvs/rpmwest/lib/python2.7/site-packages/celery/events/snapshot.py", line 73, in capture
self.state.freeze_while(self.shutter, clear_after=self.clear_after)
File "/Users/andres/.virtualenvs/rpmwest/lib/python2.7/site-packages/celery/events/state.py", line 293, in freeze_while
return fun(*args, **kwargs)
File "/Users/andres/.virtualenvs/rpmwest/lib/python2.7/site-packages/celery/events/snapshot.py", line 70, in shutter
self.on_shutter(self.state)
File "/Users/andres/.virtualenvs/rpmwest/lib/python2.7/site-packages/djcelery/snapshot.py", line 129, in on_shutter
transaction.commit()
File "/Users/andres/.virtualenvs/rpmwest/lib/python2.7/site-packages/django/db/transaction.py", line 152, in commit
connection.commit()
File "/Users/andres/.virtualenvs/rpmwest/lib/python2.7/site-packages/django/db/backends/__init__.py", line 242, in commit
self.set_clean()
File "/Users/andres/.virtualenvs/rpmwest/lib/python2.7/site-packages/django/db/backends/__init__.py", line 184, in set_clean
raise TransactionManagementError("This code isn't under transaction management")
TransactionManagementError: This code isn't under transaction management
[2013-11-19 15:19:45,010: WARNING/MainProcess] Substantial drift from celery@Lyn.local may mean clocks are out of sync. Current drift is
50400 seconds. [orig: 2013-11-19 15:19:45.010442 recv: 2013-11-19 01:19:45.009564]
最佳答案
您是否遵循了 django/celery 集成的新指南? http://docs.celeryproject.org/en/master/django/first-steps-with-django.html
我将我的项目转换为不再调用 djcelery.setup_loader() ,而是现在在 {project}/{project}/celery.py 下有一个 celery.py
另外,您的 CELERY_RESULT_BACKEND 设置为多少?我将我的设置为 djcelery.backends.database:DatabaseBackend
你的大时钟漂移可能与此有关吗?您是否尝试过同步时钟?
我正在使用 celerycam 运行 django 1.6.1,没有任何问题。
关于python - Celerycam 错误 - 此代码不在事务管理之下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20083090/