gpt4 book ai didi

python - 在多处理 pool.starmap 中传递字符串列表时出错

转载 作者:行者123 更新时间:2023-12-05 03:00:36 27 4
gpt4 key购买 nike

我正在尝试一些网页抓取。我正在将包含 URL 的列表传递给 pool.starmap ,但我遇到了参数错误。显示我的代码的简化版本:

有人可以帮我解决这个问题吗?对不起,如果我做了一些愚蠢的事情。


from multiprocessing.dummy import Pool

def func(x):
print(x)

s = ["cat","foo","bar","you","and","me"] #this list contains ~50 URLs in actual code

with Pool() as pool:
pool.starmap(func,s)

这给我错误:

Traceback (most recent call last):                                                                                                          
File "g.py", line 8, in <module>
pool.starmap(func,s)
File "C:\Users\Gunjan\Anaconda3\lib\multiprocessing\pool.py", line 274, in starmap return
self._map_async(func, iterable, starmapstar, chunksize).get()
File "C:\Users\Gunjan\Anaconda3\lib\multiprocessing\pool.py", line 644, in get
raise self._value
File "C:\Users\Gunjan\Anaconda3\lib\multiprocessing\pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "C:\Users\Gunjan\Anaconda3\lib\multiprocessing\pool.py", line 47, in starmapstar
return list(itertools.starmap(args[0], args[1]))
TypeError: func() takes 1 positional argument but 3 were given

最佳答案

starmap 需要可迭代列表。检查here .所以请改用 map

关于python - 在多处理 pool.starmap 中传递字符串列表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56686730/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com