获取方法:
tasks.get(),
异常现象:
TypeError: _iter_meta() got an unexpected keyword argument 'timeout'
解决方法:
添加sleep():
while not res.successful():sleep(0.1)
print(res.get(), # returns resultres.id, # returns task id (str)res.status, # returns task status (str)res.info # returns task information
)
# Imports
from tasks import length
from time import sleep# 0
res = length.delay('alternative_0')
while not res.status == 'SUCCESS':sleep(0.5)
# result.wait(timeout=None, interval=0.5) is the same \
# thing as the above code!
print(res.get(), # returns resultres.id, # returns task id (str)res.status, # returns task status (str)res.info # returns task information
)
# 1
res = length.delay('alternative_1')
while not res.ready():sleep(0.3)print(res.get(),res.task_id, # returns task id (str)res.ready(), # returns task is ready? (boolean)res.info
)
# 2
res = length.delay('alternative_2')
while not res.successful():sleep(0.1)print(res.get(),res.id,res.successful(), # returns task is ready? (boolean)res.info
)# OUTPUT# 13 cdece656-372b-46c2-9956-5b6c8a296a7f SUCCESS 13
# 13 1634167e-9aee-42c3-8bd9-828b34525a99 True 13
# 13 f086e8f7-7a1b-42b6-98f3-362f43a1cbfd True 13
然后获取数据就正常。
原因:
tasks方法不能执行它的任务,我们自己可以选择等待,直到函数完成。
参考:
https://www.erdoganyoksul.com/turkish_topics/2020/03/09/iter_meta.html