Python 多处理池.map()已获取;TypeError:列表索引必须是整数,而不是str";

Python 多处理池.map()已获取;TypeError:列表索引必须是整数,而不是str";,python,multiprocessing,Python,Multiprocessing,我使用python的multiprocessing.Pool模块进行了多处理,但得到了TypeError:list索引必须是整数,而不是strError: 这是我的密码: def getData(qid): r = requests.get("http://api.xxx.com/api?qid=" + qid) if r.status == 200: DBC.save(json.loads(r.text)) def getAnotherData(qid

我使用python的
multiprocessing.Pool
模块进行了多处理,但得到了
TypeError:list索引必须是整数,而不是str
Error:

这是我的密码:

 def getData(qid):
     r = requests.get("http://api.xxx.com/api?qid=" + qid)
     if r.status == 200:
        DBC.save(json.loads(r.text))

 def getAnotherData(qid):
     r = requests.get("http://api.xxxx.com/anotherapi?qid=" + qid)
     if r.status == 200:
        DBC.save(json.loads(r.text))

 def getAllData(qid):
     print qid
     getData(str(qid))
     getAnotherData(str(qid))


 if __name__ == "__main__":
     pool = Pool(processes=200)
     pool.map(getAllData, range(10000, 700000))
运行代码一段时间(不是立即)后,将抛出异常

pool.map(getAllData, range(10000, 700000))
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 251, in map
    return self.map_async(func, iterable, chunksize).get()
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 567, in get
    raise self._value
TypeError: list indices must be integers, not str

有什么不对劲吗?这是
模块的错误吗?

当工作任务引发异常时,
捕获异常,将其发送回父进程,并重新确认异常,但这不会保留原始回溯(因此您只需查看它在父进程中的重新确认位置,这不是很有帮助)。猜测一下,
DBC.save
中的某个东西期望从JSON加载的值是
int
,实际上是
str

如果要查看真正的回溯,请在顶层导入回溯,并将辅助函数的顶层更改为:

def getAllData(qid):
    try:
        print qid
        getData(str(qid))
        getAnotherData(str(qid))
    except:
        traceback.print_exc()
        raise
因此,你可以在工作者身上看到真正的回溯,而不仅仅是父母身上绝育的、大部分无用的回溯