【问题标题】:Python multiprocessing.Pool() gives out errorPython multiprocessing.Pool() 给出错误
【发布时间】:2019-07-05 08:47:51
【问题描述】:

我使用的是 python 2.7.14,需要跨多个进程生成一个方法。 我尝试使用多处理:

from multiprocessing import Pool
pool = Pool()

这给出了以下错误:

File "sw\lib\multiprocessing\__init__.py", line 232, in Pool
return Pool(processes, initializer, initargs, maxtasksperchild)
File "sw\lib\multiprocessing\pool.py", line 61, in __init__
self._repopulate_pool()
File "sw\lib\multiprocessing\pool.py", line 25, in _repopulate_pool
w.start()
File "sw\lib\multiprocessing\process.py", line 130, in start
self._popen = Popen(self)
File "sw\lib\multiprocessing\forking.py", line 272, in __init__
prep_data = get_preparation_data(process_obj._name)
File "<console>", line 2, in _get_preparation_data
File "sw\lib\multiprocessing\forking.py", line 409, in get_preparation_data
not d['sys_argv'][0].lower().endswith('pythonservice.exe'):
IndexError: list index out of range

这是 python 2.7 的错误吗?

在 python 中是否有用于多处理的替代方案?

【问题讨论】:

    标签: python python-2.7 parallel-processing python-multiprocessing failed-installation


    【解决方案1】:

    我曾经在Anaconda安装python时遇到过这样的库丢失。对此的建议是重新安装Anaconda,以便重新安装丢失的包。

    PoolLockSemaphore 是多处理器的封装器,它们实际上封装了进程以控制 CPU 使用率、RAM 和计算机的其他容量。使用方法可以查看这篇文章https://realpython.com/intro-to-python-threading/

    【讨论】:

      【解决方案2】:

      我可以在我的 python 2.7.14 中使用 Pool 进行多处理。 你可以尝试在 conda 环境中创建相同的,看看它是否有效

      conda create -n test2.7 python=2.7.14
      source activate test2.7
      

      现在打开 python shell 看看它是否有效

      from multiprocessing import Pool
      pool = Pool()
      

      【讨论】:

        【解决方案3】:

        问:这是 python 2.7 的错误吗?
        答:不,这不是错误,
        很可能您的 localhost 安装状态已损坏

        观察:

        您的 py2.7 System-under-Test (SuT):
        FAIL / EXC'ed:SuT 由于未能找到 pythonservice.exe 而抛出异常Pool() 实例化期间的 文件。 localhost 系统没有这样的文件,不能像上面演示的那样继续并抛出一个 Exc:

        File "sw\lib\multiprocessing\forking.py", line 409, in get_preparation_data
              not d['sys_argv'][0].lower().endswith('pythonservice.exe'):
        IndexError: list index out of range
        

        标准 py2.7 SuT
        通过

        Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
        Type "help", "copyright", "credits" or "license" for more information.
        >>> from multiprocessing import Pool
        >>> pool = Pool()
        >>>
        

        评估:

        Python 2.7 解释器能够在没有任何警告和/或错误的情况下执行 MCVE 代码。该问题特定于 your-py2.7-SuT,一般无法重现,并且观察表明 your-py2.7-SuT 存在缺陷,很可能是由于 python 生态系统安装的损坏状态(EXC 报告缺少一些文件,即否则公平地假设始终存在是这样的生态系统)。

        Q.E.D.

        问:python 中是否有用于多处理的替代方案?

        正确的步骤是修复(通过完全重新安装)localhost python 安装,因为它已显示已损坏。

        强烈建议使用任何现代包管理框架(mini-conda、conda 等),以确保使用正确的配置管理和版本控制工具来防止新安装的混合版本不兼容和再次出现会产生任何类似的不良副作用。

        【讨论】:

          猜你喜欢
          • 2014-09-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-09-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多