簡體   English   中英

Python multiprocessing.Pool()發出錯誤

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

我使用的是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中是否有用於多處理的替代方法?

我曾經在Anaconda安裝python時遇到過這樣的庫丟失的情況。 建議重新安裝Anaconda以便重新安裝缺少的軟件包。

PoolLockSemaphore是多處理器的包裝程序,它實際上包裝進程以控制CPU使用率,RAM和計算機的其他容量。 您可以查看有關如何使用它的本文https://realpython.com/intro-to-python-threading/

我可以在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()

問:這是python 2.7的錯誤嗎?
答:不,這不是錯誤,
您的localhost安裝狀態很可能已損壞

意見:

您的py2.7被測系統 (SuT):
失敗/執行錯誤:由於在Pool()實例化期間找不到pythonservice.exe文件, pythonservice.exe拋出了異常。 沒有此類文件的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的,一般而言無法再現,並且觀察結果表明您的py2.7-SuT存在缺陷,很可能是由於python生態系統安裝狀態損壞(EXC報告缺少某些文件,否則,可以假設這樣的生態系統總是存在的。

QED

問:python中是否有用於多處理的替代方法?

正確的步驟是修復(通過完全重新安裝) localhost python安裝,因為它已顯示其已損壞。

強烈建議使用任何現代程序包管理框架(mini-conda,conda等),以確保使用正確的配置管理和版本控制工具來防止新安裝的版本不兼容以及任何類似的雜物重新出現的副作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM