多进程multiprocessing.Pool(7).map测试

import logging

logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s-%(filename)s[line:%(lineno)d]-%(levelname)s:%(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S')
logger = logging.getLogger()
import time
from multiprocessing import Pool
from matplotlib import pyplot as plt


def itest(i):

    time.sleep(0.005)


if __name__ == "__main__":

    logger.info('begin')
    res = []
    for i in range(2, 33, 2):
        st = time.time()
        with Pool(i) as mp:
            mp.map(itest, range(1000))
        res.append(time.time() - st)
        logger.info(f'mp-{i}')

    fig = plt.figure()
    plt.plot(res)
    plt.show()
    # for i in range(1000):
    #     itest(i)
    logger.info('finished')

 

posted @ 2023-07-11 14:31  ddzhen  阅读(54)  评论(0编辑  收藏  举报