Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当我转到concurrent.futures时,无法在函数中使用项对_Python_Python 3.x_Concurrent.futures - Fatal编程技术网

Python 当我转到concurrent.futures时,无法在函数中使用项对

Python 当我转到concurrent.futures时,无法在函数中使用项对,python,python-3.x,concurrent.futures,Python,Python 3.x,Concurrent.futures,我试图在下面的脚本中使用concurrent.futures。其中有两个函数make_requests()和get_info()。当make_requests()函数产生链接和代理列表时,我打算在get_info()函数中传递它们 通常是这样的: if __name__ == '__main__': # "proxy_lists" is the holder of different proxies proxies = [proxy_lists] # make_requ

我试图在下面的脚本中使用
concurrent.futures
。其中有两个函数
make_requests()
get_info()
。当
make_requests()
函数产生
链接和
代理列表时,我打算在
get_info()
函数中传递它们

通常是这样的:

if __name__ == '__main__':
    # "proxy_lists" is the holder of different proxies
    proxies = [proxy_lists]

    # make_requests() function yields "links" and "proxy_list"
    for item,elem in make_requests(url,proxies):

        # pass "links" and "proxy_list" to get_info() function
        get_info(item,elem)
我没有发现使用
concurrent.futures
做同样的事情的想法,因为它需要一个成对的循环,通过这个
make\u requests()
函数生成两种类型的元素,然后在
get\u info()
函数中传递这两种类型的元素,就像我上面做的那样:

import concurrent.futures

if __name__ == '__main__':
    proxies = [proxy_lists]

    with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
        future_to_url = {executor.submit(get_info,link): link for link in make_requests(url,proxies)}
        concurrent.futures.as_completed(future_to_url)

当我使用
concurrent.futures
时,如何传递
get\u info()
函数中的一对项目?

我想你只想做:
executor.submit(get\u info,*link)

这是因为记录如下:

submit(fn、*args、**kwargs)

将可调用的fn调度为fn(*args**kwargs)

这使用标准来确保一切都经过
fn

*链接
链接
视为一个序列,将其解包为
提交
的参数,然后当它最终调用
fn