我正在尝试实现多处理模块以使用大型csv文件.我正在使用
Python 2.7并遵循
here的示例.
我运行了未经修改的代码(为方便起见,下面复制了代码)并注意到worker函数中的print语句不起作用.无法打印使得难以理解流程和调试.
任何人都可以解释为什么打印不在这里工作? pool.map不执行打印命令吗?我在网上搜索但没有找到任何表明这一点的文件.
import multiprocessing as mp
import itertools
import time
import csv
def worker(chunk):
# `chunk` will be a list of CSV rows all with the same name column
# replace this with your real computation
print(chunk) #
print 'working' #
return len(chunk)
def keyfunc(row):
# `row` is one row of the CSV file.
# replace this with the name column.
return row[0]
def main():
pool = mp.Pool()
largefile = 'test.dat'
num_chunks = 10
results = []
with open(largefile) as f:
reader = csv.reader(f)