import multiprocessing

def worker(num):
    """执行任务的函数"""
    print('Worker %d is running' % num)

if __name__ == '__main__':
    # 创建进程池,最大进程数为3
    pool = multiprocessing.Pool(processes=3)

    # 执行任务
    for i in range(5):
        pool.apply_async(worker, (i,))

    # 关闭进程池,防止新的任务加入
    pool.close()
    # 等待所有任务完成
    pool.join()