我正在尝试将多重处理应用于功能。有打印功能,但未显示。
import json
import os
import multiprocessing as mp
def file_subreddit_comments(rfname):
wfname = rfname + "_ext_com.txt"
return wfname
defaultFilePath = r'D:\Users\Jonathan\Desktop\Reddit Data\Run Comments\\'
directory = os.fsencode(defaultFilePath)
list_submission_id = []
submission_id_file = r'D:\Users\Jonathan\Desktop\Reddit Data\Manipulated Data-09-03-19-Final\UniqueIDSubmissionsList-09-03-2019.txt'
with open(submission_id_file, "r", encoding="utf8") as sif:
for i, l in enumerate(sif):
list_submission_id.append(l.rstrip())
new_submission_list_dir = []
for file in os.listdir(directory):
filename = os.fsdecode(file)
comment_path_read = defaultFilePath + filename
new_submission_list_dir.append(comment_path_read)
with mp.Pool(mp.cpu_count()-1) as p:
results = p.map(file_subreddit_comments, [row for row in new_submission_list_dir])
print(results)
new_submission_list_dir
包含要传递给功能file_subreddit_comments
的所有文件的列表。我已经运行了一段时间的代码,但是print(results)