一共要运行很多个任务,不用进程池怕最大进程数量限制,用进程池又不会啊
from multiprocessing import Pool, Process
import time
def print_run(msg):
print('msg.%s' % msg)
time.sleep(2)
def print_log(msg):
p = Process(target=print_run,
args=(msg,))
p.start()
p.join()
print('msg is : %s' % msg)
time.sleep(1)
def set_multprocess():
pool = Pool(processes=10)
for i in range(20):
pool.apply_async(func=print_log, args=(str(i),))
pool.close()
pool.join()
print('finished')
if __name__ == '__main__':
set_multprocess()