当前位置:   article > 正文

python 的多线程使用_results = pool.map()

results = pool.map()
  1. import requests
  2. import re
  3. #import multiprocessing
  4. #form multiprocessing.dummy import Pool
  5. from multiprocessing.dummy import Pool as ThreadPool
  6. def calc_power2(num):
  7. return num * num
  8. pool = ThreadPool(3)
  9. origin_num = [x for x in range(10)]
  10. print("the ",origin_num,"\n")
  11. result = pool.map(calc_power2,origin_num)
  12. print(result)

构造一个列表

origin_num = [ x for x in range(10) ]

pool的map方法使用传入两个参数,一个函数名和list

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/74919
推荐阅读
相关标签
  

闽ICP备14008679号