我正在尝试为外部排序问题实现生产者-消费者解决方案。我有三个二进制文件,它们可以分解文件,对一个文件进行排序,还有一个二进制文件可以合并两个文件。下面是我的排序多处理池实现:
files = [a list of files generated after running splitter binary]
pool = Pool(args["numthreads"])
pool.map(sort_file, files)
pool.close()
pool.join()
下面是我的排序文件函数:
def sort_file(file):
cmd = ["./file_sort"] + [file]
print('executing: %s')%' '.join(cmd)
subprocess.call(cmd)
这是预期的工作,但我无法使类似的模式工作的合并_文件功能,它消耗两个文件从列表中创建一个新的文件,该文件应追加回列表。我的合并文件代码如下所示:
def merge_file(file1, file2):
cmd = ["./merger"] + [file1, file2]
out, err, ecode = execute_commands(cmd)
next_file.put(out) #This is the merged file which will be appended back to list
目前没有回答
相关问题 更多 >
编程相关推荐