利用python的“多处理”模块来分配cpu密集型任务的set实用程序
para的Python项目详细描述
#段落(llel)处理实用程序 这个库实现了一组简单的并行处理实用程序 利用python的多处理模块来分布处理 在一台机器上有多个CPU。最显著的特点 library是map()函数,可用于分配CPU密集型 在多个核心上处理项目集合。
- installationpip install para
##基本用法
>>> import para >>> import gzip >>> >>> items = ["examples/big-file1.gz", "examples/big-file2.gz", ... "examples/big-file3.gz"] >>> def log_lines(path): ... with gzip.open(path, 'rt') as f: ... for lineno, line in enumerate(f): ... if len(line) > 50: ... yield path, lineno, line ... >>> for path, lineno, line in para.map(log_lines, items): ... print(path, lineno, repr(line)) ... examples/big-file1.gz 2 'this line is going to be much longer than 80 chars -- at least I hope it will\n' examples/big-file3.gz 0 'again with the long lines -- this is going to show up in the output, I hope\n'
##作者 *亚伦·哈法克–https://github.com/halfak