简体   繁体   English

Python multiprocessing.Pool()发出错误

[英]Python multiprocessing.Pool() gives out error

I am using python 2.7.14 and need to spawn a method across multiple processes. 我使用的是python 2.7.14,需要在多个进程中产生一个方法。 I tried using multiprocessing: 我尝试使用多处理:

from multiprocessing import Pool
pool = Pool()

This give out the following error: 这给出了以下错误:

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

Is this a bug with python 2.7? 这是python 2.7的错误吗?

Is there an alternative in python for multiprocessing? python中是否有用于多处理的替代方法?

I used to experience library missing like this when installing python by Anaconda . 我曾经在Anaconda安装python时遇到过这样的库丢失的情况。 The recommendation for this is to re-install Anaconda so that the missing package will be installed again. 建议重新安装Anaconda以便重新安装缺少的软件包。

Pool , Lock & Semaphore are multi-processors' wrapper that actually wrap processes to control CPU usage, RAM and other capacity of your computer. PoolLockSemaphore是多处理器的包装程序,它实际上包装进程以控制CPU使用率,RAM和计算机的其他容量。 You can check this article on how to use it https://realpython.com/intro-to-python-threading/ 您可以查看有关如何使用它的本文https://realpython.com/intro-to-python-threading/

I am able to use Pool in multiprocessing with my python 2.7.14. 我可以在python 2.7.14的多处理中使用Pool。 Can u try creating the same in a conda environment and see if it works 您能在conda环境中尝试创建相同内容,看看是否可行

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

Now open python shell and see if it works 现在打开python shell,看看它是否有效

from multiprocessing import Pool
pool = Pool()

Q: Is this a bug with python 2.7? 问:这是python 2.7的错误吗?
A: No, this is not a bug, 答:不,这不是错误,
most probably the state of your localhost installation is corrupted 您的localhost安装状态很可能已损坏

OBSERVATIONS: 意见:

Your py2.7 System-under-Test (SuT): 您的py2.7被测系统 (SuT):
FAIL / EXC'ed: SuT resorted to throw an Exception as it failed to find a pythonservice.exe file during a Pool() instantiation. 失败/执行错误:由于在Pool()实例化期间找不到pythonservice.exe文件, pythonservice.exe抛出了异常。 The localhost system, not having such file, cannot proceed as was demonstrated above and threw an Exc: 没有此类文件的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

Standard py2.7 SuT : 标准py2.7 SuT
PASS 通过

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

ASSESSMENT: 评定:

Python 2.7 interpreter is capable to execute the MCVE-code without any warning and/or errors. Python 2.7解释器能够执行MCVE代码,而不会发出任何警告和/或错误。 The problem is specific to your-py2.7-SuT, not reproducible in general and observations indicate your-py2.7-SuT is flawed, most probably due to corrupted state of the python ecosystem installation ( EXC was reporting missing some files, that were otherwise fair to be assumed to be always present is such ecosystem ). 该问题是特定于your-py2.7-SuT的,一般而言无法再现,并且观察结果表明您的py2.7-SuT存在缺陷,很可能是由于python生态系统安装状态损坏(EXC报告缺少某些文件,否则,可以假设这样的生态系统总是存在的。

QED QED

Q: Is there an alternative in python for multiprocessing? 问:python中是否有用于多处理的替代方法?

The proper step is to repair ( by a full reinstall ) the localhost python installation, as it has shown itself to be corrupted. 正确的步骤是修复(通过完全重新安装) localhost python安装,因为它已显示其已损坏。

Using any of the contemporary package management framework ( mini-conda, conda et al ) is strongly encouraged, so as to be sure of proper configuration management and version control tools are used to prevent your new installation from mixed-version incompatibilities and any similar unwanted side-effects from re-appearance. 强烈建议使用任何现代程序包管理框架(mini-conda,conda等),以确保使用正确的配置管理和版本控制工具来防止新安装的版本不兼容以及任何类似的杂物重新出现的副作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM