线程ThreadPoolExecutor与进程ProcessPoolExecutor

###################### 线程池 ############
from concurrent.futures import ThreadPoolExecutor
import time
def task(arg):
    print(arg)
    time.sleep(1)

pool = ThreadPoolExecutor(5)

for i in range(50):
    pool.submit(task,i)

#################################################

############################# 进程池 #################
from concurrent.futures import ProcessPoolExecutor
import time
def task(arg):
    print(arg)
    time.sleep(1)
if __name__ == '__main__':
    pool = ProcessPoolExecutor(3)

    for i in range(50):
        pool.submit(task,i)

 

posted @ 2018-06-30 10:40  阜阳小全  阅读(123)  评论(0编辑  收藏  举报