python多线程简单示例

open_run的头像 open_run 1 2016-04-21 15:45 7

 基本信息

× 1    × 1   

浏览数: 29459

分享时间: 2 年 前

6
#!/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 '结束!'

 

有用,谢谢~~
2 年 前 1359005646
不错,谢谢
2 年 前 qqsyj521
不错!
2 年 前 jordanmjw
可以
1 年 前 a731578543

12 [下一页]

  • trangctp的头像 trangctp 2018-08-29 15:40 代码数:0

    Life is not pink and more people have realized that. The larger the more people feel they are disadvantaged, have always been treated unfairly and betrayed by those around them. 

    whatsapp baixar gratis

  • trangctp的头像 trangctp 2018-08-29 15:42 代码数:0

    Life is not pink and more people have realized that. The larger the more people feel they are disadvantaged, have always been treated unfairly and betrayed by those around them. 

    whatsapp baixar gratis

  • trangctp的头像 trangctp 2018-08-29 15:43 代码数:0

    I know what to do so I will try. Even though my job is not right, it is an effort. To overcome it, I had to be content with life now, satisfied with what is there. 

    whatsapp baixar gratis

  • 威兹曼的头像 威兹曼 2016-05-25 12:33 代码数:0

  • 547240561的头像 547240561 2016-06-05 17:54 代码数:0

  • wxx199702的头像 wxx199702 2018-03-13 22:40 代码数:0

    写的不错

  • annashetty的头像 annashetty 2018-04-05 14:55 代码数:0

    写的不错
    cool math games

  • xgongji的头像 xgongji 2016-08-04 19:58 代码数:0

    写的不错,新手看看

  • ossaa的头像 ossaa 2018-08-05 23:06 代码数:0

    I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit.

    מנעולן בקריות

  • couponsweb的头像 couponsweb 2018-08-10 20:05 代码数:0

    Thank you so much for publishing this great stuff. I totally appreciate your work. keep doing.

    Tillys Offers 
     

    最后编辑 1 个月 前

您的评论: