python在前面写过多线程的库threading:
python3多线程趣味详解
但是今天发现一个封装得更加简单暴力的多进程库concurrent.futures:
# !/usr/bin/python3.4 # -*- coding: utf-8 -*- from concurrent.futures import ThreadPoolExecutor import time def f1(a): time.sleep(2) print(a) return 1 pool=ThreadPoolExecutor(5) for i in range(30): a=pool.submit(f1,i)
运行结果部分: