【发布时间】:2017-02-09 11:03:30
【问题描述】:
我有一个函数,我想用池创建多线程。
def find(item):
curve=Curve(item)
return curve._find()
多线程版本会检查输入是否为列表:
def find(item):
if type(item) == list:
items=item
pool = ThreadPool(len(items))
curves = pool.map(Curve, moniker)
pool.close()
pool = ThreadPool(len(items))
# now comes the tricky part:
results = pool.map(???) # curves is a list of class
# with each having _find as a function
pool.close()
return results
else:
curve=Curve(item)
return curve._find()
如何使用上述类列表调用 pool.map?
【问题讨论】:
标签: python multithreading threadpool