在 wsl 中使用多进程时名称解析暂时失败

问题描述 投票:0回答:1

问题:

运行此示例代码时:

要重现的代码示例

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))

运行多进程似乎有问题,因为当我运行它时,我收到“名称解析暂时失败”

vscode fail code on

其他信息:

###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]

环境信息

  • Python 3.8.10
  • vscode 1.69.0
  • Ubuntu 20.04
  • WSL1
  • Microsoft Windows [版本 10.0.19043.2006]
  • Linux 版本 4.4.0-19041-Microsoft([电子邮件受保护])(gcc 版本 5.4.0 (GCC))

只是大声声明问题文档,DNS 不应该失败,这就是我想要在这里解决的问题。

有关此事的任何帮助都会有帮助。

谢谢你。

python python-3.x windows-subsystem-for-linux ubuntu-20.04 openmpi
1个回答
0
投票

简单地做

wsl --shutdown
来自 powershell 并再次重新启动 wsl,它会正常工作

© www.soinside.com 2019 - 2024. All rights reserved.