from multiprocessing import Pool,current_process
import time
def fun1(name):
print(f"id1为{current_process().pid},接受的数据为{name}")
time.sleep(3)
return name
def fun2(args):
print(args)
if __name__ == '__main__':
pllo=Pool(3)
pllo.apply_async(fun1,args=('1',),callback=fun2,)
pllo.apply_async(fun1,args=('2',))
pllo.apply_async(fun1,args=('3',))
pllo.apply_async(fun1,args=('4',))
pllo.apply_async(fun1,args=('5',))
pllo.apply_async(fun1,args=('6',))
pllo.apply_async(fun1,args=('7',))
pllo.apply_async(fun1,args=('8',))
pllo.apply_async(fun1,args=('9',))
pllo.close()
pllo.join()
#老师好 这里有时候打印不出数据是怎末回事呢 是一个空行 如下:
#id1为7628,接受的数据为1id1为7628,接受的数据为1
id1为16176,接受的数据为2
id1为7092,接受的数据为3
1id1为7628,接受的数据为4
id1为16176,接受的数据为5
id1为7092,接受的数据为6
id1为7628,接受的数据为7
id1为16176,接受的数据为8
id1为7092,接受的数据为9
进程已结束,退出代码为 0