• python3 用multiprocessing模块传递多个参数


    from datetime import datetime
    from time import sleep
    import numpy as np
    import multiprocessing
    # from multiprocessing.dummy import Pool as ThreadPool
    
    
    def func(x, y, z):
        sleep(3)
        return x+y, z
    
    
    if __name__ == '__main__':
        pool = multiprocessing.Pool(processes=6)
        x = np.zeros((6, 1), dtype=int)
        y = np.zeros((6, 1), dtype=int)
        z = np.zeros((6, 1), dtype=int)
        result = []
    
        for i in range(6):
            x[i,0] = i
            y[i,0] = i
            z[i,0] = i
    
        xx = np.squeeze(x)
        yy = np.squeeze(y)
        zz = np.squeeze(z)
        c = list(zip(xx, yy, zz))
        print(c)
        cc = np.array(c)
        # print(cc)
        # d = [(0, 0, 0), (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5)]
        print(datetime.now())
        result = pool.starmap(func, c)
        print(result)
        print(datetime.now())

    # from functools import partial
    #
    # def sum(a, b, c):
    # return a + b + c
    #
    # a = 'abc'
    # b = "ABC"
    # c = "123"
    # pa = partial(sum, a)
    # re = pa(b, c)
    #
    # print(re)
  • 相关阅读:
    Webdriver API之元素定位
    学生XX码
    网站设计基础
    JS基础知识
    1、变量和基本类型
    网上地址下载图片
    网上地址下载图片2
    微信账号
    INSERT INTO SELECT语句与SELECT INTO FROM语句
    【基础知识】创建匹配游戏
  • 原文地址:https://www.cnblogs.com/karl-python/p/15044499.html
Copyright © 2020-2023  润新知