本文整理匯總了Python中threadpool.ThreadPool方法的典型用法代碼示例。如果您正苦於以下問題:Python threadpool.ThreadPool方法的具體用法?Python threadpool.ThreadPool怎麽用?Python threadpool.ThreadPool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類threadpool
的用法示例。
在下文中一共展示了threadpool.ThreadPool方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: import threadpool [as 別名]
# 或者: from threadpool import ThreadPool [as 別名]
def run(self):
#默認為10線程掃描
pool = threadpool.ThreadPool(10)
#迭代任務隊列
requests = threadpool.makeRequests(self.call_scan,self.list_renwu)
print 'add pool ok'
for req in requests:
pool.putRequest(req)
print '---------------------ok----------------------'
pool.wait()
print '---------------------done--------------------'
#處理單個掃描任務記錄進度
示例2: __init__
# 需要導入模塊: import threadpool [as 別名]
# 或者: from threadpool import ThreadPool [as 別名]
def __init__(self, concurrency=10):
self.concurrency = concurrency
self.jobPool = tp.ThreadPool(num_workers=concurrency)
self.errNum = 0
self.successNum = 0
self.totalNum = 0
self.results = {}
示例3: mThreadExecute
# 需要導入模塊: import threadpool [as 別名]
# 或者: from threadpool import ThreadPool [as 別名]
def mThreadExecute(self, threadcount=10,canexecute=True):
import threadpool
pool = threadpool.ThreadPool(threadcount)
seed= parallel_map(self,canexecute);
def Funcs(item):
task= parallel_reduce(self,[item],canexecute);
print('totalcount: %d'%len([r for r in task]));
print('finish' + str(item));
requests = threadpool.makeRequests(Funcs, seed);
[pool.putRequest(req) for req in requests]
pool.wait()
# self.__close__()
示例4: __init__
# 需要導入模塊: import threadpool [as 別名]
# 或者: from threadpool import ThreadPool [as 別名]
def __init__(self, seed_file, func2run, options=None,
result_file='result.txt',
thread_num=100, verbose=True):
self.func2run = func2run
self.options = options if options else self.default_options
self.seed_iter = open(seed_file, 'rbU')
self.total_num = 0
self.result_fobj = open(result_file, 'wb')
self.finished_num = 0
self.err_num = 0
self.success_num = 0
self.tp = threadpool.ThreadPool(num_workers=thread_num)
示例5: exec_multi_threading
# 需要導入模塊: import threadpool [as 別名]
# 或者: from threadpool import ThreadPool [as 別名]
def exec_multi_threading(size, proxys):
pool = threadpool.ThreadPool(size)
reqs = threadpool.makeRequests(GetFreeProxy.validUsefulProxy, proxys)
[pool.putRequest(req) for req in reqs]
pool.wait()
示例6: start_service
# 需要導入模塊: import threadpool [as 別名]
# 或者: from threadpool import ThreadPool [as 別名]
def start_service(love):
import threadpool
pool = threadpool.ThreadPool(2)
reqs = threadpool.makeRequests(super_hero, [love])
[pool.putRequest(req) for req in reqs]
reqs = threadpool.makeRequests(girl_of_the_night, [love])
[pool.putRequest(req) for req in reqs]
pool.wait()
示例7: __init__
# 需要導入模塊: import threadpool [as 別名]
# 或者: from threadpool import ThreadPool [as 別名]
def __init__(self, capacity = 10):
try:
import threadpool
except:
print('threadpool is not install. Please run:')
print('\t pip install threadpool --user')
self.num_threads = capacity
self.pool = threadpool.ThreadPool(10)