运行此示例代码时:
要重现的代码示例
import requests
def worker(url):
r = requests.get(url)
return r.status_code
def run_workers_for_lst(url_lst: list):
with mp.Pool(processes=mp.cpu_count()) as pool:
results = pool.map(worker, url_lst)
return dict(zip(url_lst, results))
if __name__ == '__main__':
url_lst = [
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=1",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=3",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=4",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=5",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=6",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=7",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=8",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=9",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=10",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=11",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=12",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=13",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=14",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=15",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=16",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=17",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=18",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=19",
"https://www.ahuzot.co.il/Parking/ParkingDetails/?ID=20",
]
print(run_workers_for_lst(url_lst=url_lst))
运行多进程似乎有问题,因为当我运行它时,我收到“名称解析暂时失败”
###openmpi
从网上看,似乎DNS名称解析与linux apt软件包中安装的openmpi软件包之间存在关系,所以我也添加了与openmpi相关的信息,尽管我运行时的DNS解析
ping google.com
工作正常很好。
$ apt list --installed | grep openmpi:
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libcaf-openmpi-3/focal,now 2.8.0-1 amd64 [installed,auto-removable]
libcoarrays-openmpi-dev/focal,now 2.8.0-1 amd64 [installed,auto-removable]
libopenmpi3/focal,now 4.0.3-0ubuntu1 amd64 [installed,automatic]
openmpi-bin/focal,now 4.0.3-0ubuntu1 amd64 [installed]
openmpi-common/focal,now 4.0.3-0ubuntu1 all [installed,automatic]
只是大声声明问题文档,DNS 不应该失败,这就是我想要在这里解决的问题。
有关此事的任何帮助都会有帮助。
谢谢你。
简单地做
wsl --shutdown
来自 powershell 并再次重新启动 wsl,它会正常工作