如何解决并发期货问题
所以我有这段代码需要使用 Concurrent.futures 模块,出于某种原因它告诉我它不存在。我查了一下,我找不到问题所在。我试过从它安装我需要的工具,认为是这样,但我只能下载其中一个。 错误信息:
from concurrent.futures import ProcessPoolExecutor ModuleNotFoundError: 没有名为“concurrent.futures”的模块; “并发”不是包
我的代码:
import requests,time
from concurrent.futures import ProcessPoolExecutor
sites = ["http://www.youtube.com"]
def get_one(site):
resp = requests.get(site)
size = len(resp.content)
print(f"download {site} bytes from {site}")
return size
def main():
total_size = 0
start = time.perf_counter()
with ProcessPoolExecutor as exec:
total_size = sum(exec.map(get_one,sites))
end = time.perf_counter()
for site in sites:
total_size += size
#print(f"downlded {size} bytes from {site}")
#end = time.perf_counter()
print(f"elapsed time: {end - start} seconds")
print (f"downloaded a totla of {total_size} bytes")
if __name__== "__main__":
main()
我知道通常当我说“来自”时应该有一个文件,但我查找的所有内容都说 concurrent.futures 是 python 的一部分,但由于某种原因,我的无法正常工作。如果它在那里,我必须安装它吗?
解决方法
我发现我的文件夹中有一个名为 concurrent.py 的文件,它把所有东西都搞砸了!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。