进程池

 

code

import os
import time
from concurrent.futures.process import ProcessPoolExecutor


def test(n):
    print(f'n:{n}-os.getpid:{os.getpid()}')
    time.sleep(2)
    return 'helllo'


def call_back(n):
    print(f'callback:n.result{n.result()}')


if __name__ == '__main__':
    pool = ProcessPoolExecutor(5)
    print('zhu')
    t_list = []
    for i in range(20):
        res = pool.submit(test, i)
        t_list.append(res)
    print(f't_list:{t_list}')

  

posted @ 2023-10-24 16:24  tslam  阅读(4)  评论(0编辑  收藏  举报