# -*- coding: utf-8 -*-
import time
from concurrent.futures import ThreadPoolExecutor
import numpy as np

start=time.clock()
list1=np.random.randint(0,100,20)
print list1

def multithreading():

    list2=[]
    with ThreadPoolExecutor(max_workers=8) as executor:
        for result in executor.map(working,list1,chunksize=10):
            print result
            list2.append(result)

    return list2



def working(num):
    time.sleep(0.2)
    return num


x=multithreading()
print x

over= time.clock()

print (over-start)

以下是单进程和多进程的比较

总耗时:python多进程应用小试

单进程:python多进程应用小试

差距明显

相关文章:

  • 2022-03-03
  • 2021-11-10
  • 2021-07-26
  • 2021-06-16
猜你喜欢
  • 2021-09-25
  • 2021-12-25
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2021-10-07
相关资源
相似解决方案