Created
March 15, 2014 06:58
-
-
Save flyer103/9562789 to your computer and use it in GitHub Desktop.
测试 ProcessPoolExecutor 异步结果的获得
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.futures.ProcessPoolExecutor 获取多进程执行的结果. | |
""" | |
import pprint | |
from concurrent.futures import ProcessPoolExecutor, as_completed | |
def ret_name(name): | |
print(name) | |
return name | |
def controller(): | |
names = ['flyer', 'flx', 'mafei', 'math', 'fei'] | |
with ProcessPoolExecutor() as executor: | |
futures = [executor.submit(ret_name, name) for name in names] | |
results = [future.result() for future in futures] | |
print('Results are:') | |
pprint.pprint(results) | |
if __name__ == '__main__': | |
controller() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment