python 多进程线程之传入多参数问题

#! /usr/bin/env python
# -*- coding: utf-8 -*-#

# -------------------------------------------------------------------------------
# Name:         tools
# Author:       yunhgu
# Date:         2021/7/1 11:06
# Description: 
# -------------------------------------------------------------------------------
from concurrent.futures import ProcessPoolExecutor, as_completed
from multiprocessing import Pool
import time
import os


def work(a):
    time.sleep(1)
    print(f"{a}:{os.getpid()}")
    return a


def main():
    with ProcessPoolExecutor(max_workers=None) as p:
        task_list = []
        for i in range(3):
            for j in range(3):
                for z in range(3):
                    a = (i, j, z)
                    task = p.submit(work, a)
                    task_list.append(task)
        for task in as_completed(task_list):
            if task.done():
                print(task.result())


if __name__ == '__main__':
    start_time = time.time()
    main()
    print(time.time() - start_time)
    # main2()
posted @ 2021-07-01 16:07  不能说的秘密  阅读(894)  评论(0编辑  收藏  举报