gpt4 book ai didi

python-3.x - 属性错误 : module 'concurrent' has no attribute 'futures' when I try parallel processing in python 3. 6

转载 作者:行者123 更新时间:2023-12-03 16:14:07 32 4
gpt4 key购买 nike

我正在尝试使用 concurrent.futures 模块将需要很长时间的进程拆分为多个进程。附上以下代码
主功能:

with concurrent.futures.ProcessPoolExecutor() as executor:
for idx, score in zip([idx for idx in range(dataframe.shape[0])],executor.map(get_max_fuzzy_score,[dataframe[idx:idx+1] for idx in range(dataframe.shape[0])])):
print('processing '+str(idx+1)+' of '+str(dataframe.shape[0]+1))
dataframe['max_row_score'].iloc[idx] = score
get_max_fuzzy_score功能:
def get_max_fuzzy_score(picklepath_or_list, df):
import numpy as np
extracted_text_columns = list(df.filter(regex='extracted_text').columns)
data_list = [df[data].iloc[0] for data in extracted_text_columns if not df[data].isnull().values.any()]
try:
size = len(picklepath_or_list)
section_snippet_list = picklepath_or_list
except:
section_snippet_list = pickle.load(open(picklepath_or_list,'rb'))
scores = []
for section_snippet in section_snippet_list:
for data in data_list:
scores.append(fuzz.partial_ratio(data,section_snippet))
score = max(scores)

return score
该函数采用几列的值并从先前构建的列表中返回最大模糊分数。
这是我得到的错误:
Traceback (most recent call last):
File "multiprocessing.py", line 8, in <module>
import concurrent.futures
File "/home/naveen/anaconda3/lib/python3.6/concurrent/futures/__init__.py", line 17, in <module>
from concurrent.futures.process import ProcessPoolExecutor
File "/home/naveen/anaconda3/lib/python3.6/concurrent/futures/process.py", line 53, in <module>
import multiprocessing
File "/home/naveen/Documents/pramata-ie/data-science/scripts/multiprocessing.py", line 79, in <module>
with concurrent.futures.ProcessPoolExecutor() as executor:
AttributeError: module 'concurrent' has no attribute 'futures'

最佳答案

您可以通过以下方式导入它:import concurrent.futures并以这种方式使用它:

executor = concurrent.futures.ThreadPoolExecutor(max_workers=num_workers)

也可以导入 ThreadPoolExecutor这边走:
from concurrent.futures.thread import ThreadPoolExecutor
并以这种方式使用它:
executor = ThreadPoolExecutor(max_workers=num_workers)

关于python-3.x - 属性错误 : module 'concurrent' has no attribute 'futures' when I try parallel processing in python 3. 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53648211/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com