https://blog.csdn.net/fly_leopard/article/details/121610641
multiprocessing提供了freeze_support来实现main module的安全导入,在运行multiprocessing创建进程前调用该方法:
....
if __name__ == '__main__':
import multiprocessing
# 该方法作用是阻止子进程运行其后面的代码
multiprocessing.freeze_support()
pool = Pool(3)
try:
log.info("Start Program.")
pool.apply_async(start_queue_manager, error_callback=error_callback)
pool.apply_async(start_server, error_callback=error_callback).ready()
pool.apply_async(start_browser, error_callback=error_callback)
except:
log.error(traceback.format_exc())
finally:
pool.close()
pool.join()
评论