如何解决带有地图的 Concurrent.futures 不使用内存
我正在尝试为一个文本处理函数执行多重处理,该函数调用其他函数从 url、clean 和 lemmatize 中提取文本。问题是词形还原步骤非常慢,我的电脑只使用了 12% 的可用 CPU。现在,使用 concurrent.futures,CPU 使用率为 100%,但内存使用率恒定为 20%。我可能做错了什么,因为所有提到使用 map 进行多处理的文献都确保 RAM 消耗非常高。
我正在实现的功能如下:
#All-in-one function
def sentence_processing(url_sentencia):
# Extract text from PDF url
text = txt_extract(url_sentencia)
# Firstly we extract the fragments
id_cendoj,año,cuestiones,materia,parte_recurrente,parte_recurrida,first_fallo,target_fallo,costas_pro,corpus = var_extract(text)
#Basic cleaning
basic_clean_corpus = corpus_clean(corpus)
#Clean the long variables: corpus and fallo
processed_corpus = token_and_lemma_text(basic_clean_corpus)
#Store the information in the SQLite db
insertVaribleIntoTable(id_cendoj,processed_corpus)
#Paralelization of the workflow: map
import concurrent.futures
with concurrent.futures.ProcessPoolExecutor() as executor:
res = executor.map(sentence_processing,url_list)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。