【发布时间】:2017-04-29 18:23:50
【问题描述】:
我有创建线程池的主线程。在调用函数之前,对池中的每个线程进行初始化。当所有线程都将被初始化时,如何等待?
例子:
from multiprocessing.pool import ThreadPool
def main():
# in main thread
pool = ThreadPool(processes=5, initializer=init_pool)
# >>> here it is I want to wait for initialized
pool.map_async(do_smth).get()
def init_pool():
# initialized new thread in pool
pass
def do_smth():
# do somethings
pass
如果发生线程初始化异常,则必须不引起map_async
【问题讨论】:
-
我可以使用多处理中的值来达到这个目的,但这不是很好的解决方案
标签: python multiprocessing threadpool