简体   繁体   English

Gearman提交多个作业AttributeError:'str'对象没有属性'get'

[英]Gearman Submit Multiple Jobs AttributeError: 'str' object has no attribute 'get'

What I'm trying to achieve here is to submit multiple jobs to Gearman and print the results returned by the workers once they are done with processing the job. 我要在这里实现的目标是,向Gearman提交多个作业 ,并在完成工作后打印出工人返回的结果

I've read through the examples on: 我已阅读以下示例:

https://pythonhosted.org/gearman/1to2.html#client-multiple-tasks https://pythonhosted.org/gearman/client.html https://pythonhosted.org/gearman/1to2.html#client-multiple-tasks https://pythonhosted.org/gearman/client.html

I then tried to implement the check_request_status in the following way: 然后,我尝试通过以下方式实现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

I'm getting the following error which I can't seem to figure out even after much Google-fu, searching through the Gearman Google Groups and poring through other people's implementation of Gearman: 我遇到了以下错误,即使经过大量Google-fu工作,我仍然无法弄清楚,搜索了Gearman Google网上论坛并仔细研究了其他人对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'

Does anyone know what's going on here? 有人知道这是怎么回事吗?

Turns out the error is a simple one. 原来错误是一个简单的错误。 In the for-loop above, simply use the append function instead of extend for adding a dict to the list_of_jobs array: 在上面的for循环中,只需使用append函数,而不要使用extend将dict添加到list_of_jobs数组中:

list_of_jobs.append(dict(task='run_task', data=str(i)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM