python线程池传参demo

import threadpool

def hello(name):
    for i in range(0,5):
        print(name+str(i))

if __name__ == "__main__":

    # print(hello("test"))
    val_pool=[]
    for i in range(0,2):
        var_dict={"name":"test"+str(i)}
        var_tup=(None,var_dict)
        val_pool.append(var_tup)

    print(val_pool)
    pool=threadpool.ThreadPool(10)
    requests = threadpool.makeRequests(hello, val_pool)
    for req in requests:
        pool.putRequest(req)

    pool.wait()

 

posted on 2022-07-04 20:19  该用户很懒  阅读(275)  评论(0编辑  收藏  举报