python多线程简单示例

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

 基本信息

× 1    × 1   

浏览数: 31550

分享时间: 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 3 [下一页]

  • victoriake的头像 victoriake 2018-10-19 19:24 代码数:0

    But really if you can't learn C++ then chances are your program is going to be rubbish. And don't expect to just magic up a program and sell it for Dissertation Writing Services UK millions. It'll take years to become good enough to make good, commercial programs.

  • 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

  • trangctp的头像 trangctp 2018-11-14 11:23 代码数:0

    I like it, thank you have shared 

    instagram app

    instagram video download

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

    写的不错,新手看看

您的评论: