2
我做Python的multiprocessing.Pool
模塊多,卻得到了TypeError: list indices must be integers, not str
錯誤:多pool.map()得到 「類型錯誤:列表索引必須是整數,而不是STR」
這裏是我的代碼:
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
出了什麼問題?它是Pool
模塊的錯誤嗎?
謝謝,夥計,真的給了我一個線索! – armnotstrong