Skip to content

Instantly share code, notes, and snippets.

@flyer103
Created March 15, 2014 07:05
Show Gist options
  • Save flyer103/9562829 to your computer and use it in GitHub Desktop.
Save flyer103/9562829 to your computer and use it in GitHub Desktop.
测试 python3.2+ 中的 ThreadPoolExecutor
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""测试使用 concurrent 提供的线程池.
"""
import time
import random
import concurrent.futures
from concurrent.futures import ThreadPoolExecutor
def worker(name):
print('First %s' % (name,))
time.sleep(random.randint(1, 3))
print('Final %s' % (name,))
with ThreadPoolExecutor(max_workers=2) as executor:
for i in range(10):
executor.submit(worker, i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment