我有創建ThreadPool的主線程。在調用函數之前,使初始化池中的每個線程。所有線程將被初始化時如何等待?等待初始化池中的所有線程
例子:
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如果發生
我可以使用值從多處理用於此目的,但它是不漂亮的解決方案 – deniska369