Python并发性:每个进程/线程之后的打印计数

时间:2018-11-28 21:26:16

标签: python multithreading

我希望我的多处理Python脚本在控制台上显示其当前进度;例如:

  

5个文件中有3个已完成

我的脚本(不完整):

import concurrent.futures

def main(file):
    # do stuff with file
    sys.stdout.write("\r%d of %d files finished" % (count, total))

if __name__ == '__main__':

    files = ['a','b','c','d','e']
    with concurrent.futures.ProcessPoolExecutor() as executor:
        executor.map(main, files)

问题-如何修改我的脚本,使其:

  1. 存储进程总数吗?
  2. 是否跟踪已完成的过程数量?
  3. 在控制台上一行打印两个数字吗?

0 个答案:

没有答案