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

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

我在这里想要实现的是向 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 组并仔细研究其他人对 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'

有人知道这里发生了什么吗?

原来是一个简单的错误。在上面的 for 循环中,只需使用 append 函数而不是 extend 来将字典添加到 list_of_jobs 数组:

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