Python Pool.map 的函数参数
Python function parameters for Pool.map
from multiprocessing import Pool
from urllib.request import urlretrieve
tmp= Pool(4).map(urlretrieve, urls)
在这种情况下,我如何指定 urlretrieve 的文件名?
如果你想指定多个参数并且你不想在函数 urlretrieve
中解压它们(你也没有访问权限)那么也许你可以尝试使用 starmap
。例如,这里我们同时传入 url
和 filename
:
from multiprocessing import Pool
from urllib.request import urlretrieve
urls = ["http://www.google.com", "http://www.yahoo.com"]
filenames = ["google.html", "yahoo.html"]
results = Pool(2).starmap(urlretrieve, zip(urls, filenames))
from multiprocessing import Pool
from urllib.request import urlretrieve
tmp= Pool(4).map(urlretrieve, urls)
在这种情况下,我如何指定 urlretrieve 的文件名?
如果你想指定多个参数并且你不想在函数 urlretrieve
中解压它们(你也没有访问权限)那么也许你可以尝试使用 starmap
。例如,这里我们同时传入 url
和 filename
:
from multiprocessing import Pool
from urllib.request import urlretrieve
urls = ["http://www.google.com", "http://www.yahoo.com"]
filenames = ["google.html", "yahoo.html"]
results = Pool(2).starmap(urlretrieve, zip(urls, filenames))