Python的threadpool模块
生活随笔
收集整理的這篇文章主要介紹了
Python的threadpool模块
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
Python的threadpool模塊
這是一個使用python實現的線程池庫。
安裝
pip?install?threadpool文檔
http://gashero.yeax.com/?p=44 http://www.chrisarndt.de/projects/threadpool/測試
使用一個20個線程的線程池進行測試
import?threadpool? import?time,random? import?Queuedef?hello1(str):?time.sleep(2)?return?str?def?print_ret(request,?result):?print?"the?result?is?%s?%r\n"?%?(request.requestID,?result)?def?deal_task(pool):try:pool.poll(True)except?Exception,?e:print?str(e)#lst?=?[1,2,3,4,5,6,7] q?=?Queue.Queue() for?i?in?range(100):q.put(i)lst?=?[q.get()?for?i?in?range(q.qsize())]pool?=?threadpool.ThreadPool(20)? requests?=?threadpool.makeRequests(hello1,?lst,?print_ret)? for?req?in?requests:pool.putRequest(req)#deal_task(pool)pool.wait()轉載于:https://my.oschina.net/crooner/blog/387933
總結
以上是生活随笔為你收集整理的Python的threadpool模块的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: KMP POJ 2752 Seek th
- 下一篇: jQuery.grep()