Created
March 15, 2014 07:05
-
-
Save flyer103/9562829 to your computer and use it in GitHub Desktop.
测试 python3.2+ 中的 ThreadPoolExecutor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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