我在这里尝试实现的目标是在完成处理工作后,向工人提交多个工作并打印返回的结果
我已经阅读了以下示例:
https://pythonhosted.org/gearman/1to2.html#client-multiple-tasks https://pythonhosted.org/gearman/client.html
然后我尝试以下列方式实现check_request_status:
list_of_jobs = []
for i in xrange(1,4,1):
list_of_jobs.extend(dict(task='run_task', data=str(i)))
completed_requests = gm_client.wait_until_jobs_completed(submitted_requests,
poll_timeout=30.0)
for job_request in completed_requests:
if job_request.complete:
print job_request.result
elif job_request.timed_out:
print "Job %s timed out!" % job_request.unique
elif job_request.state == JOB_UNKNOWN:
print "Job %s connection failed!" % job_request.unique
我收到了以下错误,即使经过Google-fu之后我也无法弄清楚,通过Gearman Google网上搜索并仔细研究其他人对Gearman的实施情况:< / p>
Traceback (most recent call last):
File "supervisor.py", line 16, in <module>
completed_requests = gm_client.submit_multiple_jobs(list_of_jobs)
File "/usr/local/lib/python2.7/dist-packages/gearman/client.py", line 48, in submit_multiple_jobs
requests_to_submit = [self._create_request_from_dictionary(job_info, background=background, max_retries=max_retries) for job_info in jobs_to_submit]
File "/usr/local/lib/python2.7/dist-packages/gearman/client.py", line 169, in _create_request_from_dictionary
job_unique = job_info.get('unique')
AttributeError: 'str' object has no attribute 'get'
有谁知道这里发生了什么?
答案 0 :(得分:0)
原来错误很简单。在上面的for循环中,只需使用append函数而不是extend来将dict添加到list_of_jobs数组中:
list_of_jobs.append(dict(task='run_task', data=str(i)))