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()
不论你在什么时候开始,重要的是开始之后就不要停止。
不论你在什么时候结束,重要的是结束之后就不要悔恨。