我使用 d,并担负着这样的任务:
class TestTask(Task):
name = "enabler.test_task"
def run(self, **kw):
debug_log("begin test task")
time.sleep(5)
debug_log("end test task")
def on_success(self, retval, task_id, args, kwargs):
debug_log("on success")
def on_failure(self, retval, task_id, args, kwargs):
debug_log("on failure")
我利用Django炮弹执行任务:
python manage.py shell
r = tasks.TestTask().delay()
从表象中可以看出,任务已经执行:
[2012-01-16 08:13:29,362: INFO/MainProcess] Got task from broker: enabler.test_task[e2360811-d003-45bc-bbf8-c6fd5692c32c]
[2012-01-16 08:13:29,390: DEBUG/PoolWorker-3] begin test task
[2012-01-16 08:13:34,389: DEBUG/PoolWorker-3] end test task
[2012-01-16 08:13:34,390: DEBUG/PoolWorker-3] on success
[2012-01-16 08:13:34,390: INFO/MainProcess] Task enabler.test_task[e2360811-d003-45bc-bbf8-c6fd5692c32c] succeeded in 5.00004410744s: None
然而,当我从伤口中检查任务时,我总是去除:
>>> r = tasks.TestTask().delay()
>>> r
<AsyncResult: e2360811-d003-45bc-bbf8-c6fd5692c32c>
>>> r.state
PENDING
>>> r.state
PENDING
>>> r.state
PENDING
>>> r.state
PENDING
尽管任务得到了很好的执行。
为什么发生这种情况?