<code id="ymukc"><xmp id="ymukc">

python多線程簡單示例

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

 基本信息

× 1    × 1   

瀏覽數: 30822

分享時間: 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 [下一頁]

  • 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

  • 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.

    ?????? ??????

您的評論:

  
六合特码资料
<code id="ymukc"><xmp id="ymukc">
<code id="ymukc"><xmp id="ymukc">