云萌主云应用官方论坛
标题:
python多线程简单示例
[打印本页]
作者:
lady-niuniu
时间:
2017-1-10 11:52
标题:
python多线程简单示例
来源:
http://www.open-open.com/code/view/1461224708346
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
import threadpool
import time,random
"""
安装threadpool
sudo easy_install threadpool
"""
def threadpool_test(arg):
# 做一些事情
time.sleep(0.01)
return arg
def print_result(request, result):
print "结果 %s %r" % (request.requestID, result)
if __name__ == "__main__":
data = ['test_%d' % i for i in range(20)]
pool = threadpool.ThreadPool(5)
requests = threadpool.makeRequests(threadpool_test, data, print_result)
for req in requests:
pool.putRequest(req)
pool.wait()
print '结束!'
复制代码
欢迎光临 云萌主云应用官方论坛 (https://yunmengzhu.com/)
Powered by Discuz! X3.4