本文整理汇总了Python中threadpool.ThreadPool.addTask方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.addTask方法的具体用法?Python ThreadPool.addTask怎么用?Python ThreadPool.addTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threadpool.ThreadPool
的用法示例。
在下文中一共展示了ThreadPool.addTask方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BBQ
# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import addTask [as 别名]
class BBQ(object):
def __init__(self,t=180,count=8):
self.time = float(t)
self.count = int(count)
self.ThreadPool = ThreadPool(self.count)
'''
实际处理烧烤任务的函数
'''
def handle(self,task):
time.sleep(self.time)#模拟烧烤时间
try:
task[0] = True
except:
pass
return
'''
添加一个烧烤任务
task格式:[True/False],
True代表处理完成
False 代表等待处理
'''
def addTask(self,task):
self.ThreadPool.addTask(self.handle,task)
示例2: list
# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import addTask [as 别名]
channels = list(db.channels.find())
client.disconnect() # probably not the most efficient, but the mongo client isn't thread safe
work_queue = Queue.Queue()
finish_events = []
tp = ThreadPool(multiprocessing.cpu_count(), queue_size=0, wait_timeout=1)
ii = ItemInserter(host, port, db_name, 'items', 'channels', work_queue, finish_events)
for channel in channels:
mod_date = None
try:
etag = channel['etag']
except KeyError:
etag = None
try:
mod_date = channel['last_modified']
except KeyError:
mod_date = None
e = threading.Event()
fp = ChannelFetcherParser(channel['url'], mod_date, etag, work_queue, e)
ii._finished.append(e)
tp.addTask(fp)
tp.addTask(ii)
work_queue.join()
tp.cleanUpThreads()