我有一个列表我想运行一个代码块,但列表长度为几千项,并且它需要太长的时间迭代它们。如何在python中同时在列表中的所有项目上运行代码块
有没有一种方法可以让我的脚本同时对该列表中的每个项目执行检查?
我的代码如下所示:
def check_url(url_loc):
response1 = requests.get(url_loc)
time.sleep(10)
response2 = requests.get(url_loc)
if response1 != response2:
print(url_loc + "has changed go check now:" + url_loc)
else:
pass
while True:
all(check_url(loc) for loc in sitelocations)
为什么你有一个'time.sleep'在你的功能?这会减慢速度。这个功能应该做什么? – qxz
@qxz这段代码似乎比较相隔10秒,因此睡眠。 – bli