我在这里想要实现的是向Gearman提交多个作业,并在工作人员完成处理作业后打印返回的结果。
我已经阅读了以下示例:
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 Groups 并仔细研究其他人对 Gearman 的实现,我似乎也无法弄清楚:
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'
有谁知道这里发生了什么?