import os
from multiprocessing import Pool
demo = 'this is a test'
def func():
with open('text.txt', 'w') as f:
f.write(demo)
print('process {} write success'.format(os.getpid()))
if __name__ == '__main__':
p = Pool(5)
for i in range(100):
# 异步,可以设置回调、函数
p1 = p.apply_async(func)
p.close()
p.join()
https://www.cnblogs.com/cwp-bg/p/7465384.html