首页 > 代码库 > python简单粗暴多线程之concurrent.futures

python简单粗暴多线程之concurrent.futures

python在前面写过多线程的库threading:

python3多线程趣味详解

但是今天发现一个封装得更加简单暴力的多线程库concurrent.futures:

# !/usr/bin/python3.4# -*- coding: utf-8 -*-from concurrent.futures import ThreadPoolExecutorimport timedef f1(a):    time.sleep(2)    print(a)    return 1pool=ThreadPoolExecutor(5)for i in range(30):    a=pool.submit(f1,i)

运行结果部分:

技术分享

 

python简单粗暴多线程之concurrent.futures