代码:
import multiprocessing
import time
class a:
def __init__(self) -> None:
self.count = 0
def aa(self,pool:'multiprocessing.pool.Pool'):
pool.apply_async(func = self.aaa, args=(), kwds={})
return True
def aaa(self):
for i in range(5):
self.count = self.count +1
print("count" ,self.count)
time.sleep(0.5)
return True
if __name__ == "__main__":
pool = multiprocessing.Pool(processes=None, initializer=None, initargs=(), maxtasksperchild=None)
qw =a()
qw.aa(pool)
while True:
print(qw.count)
time.sleep(1)
打印结果:
0
count 1
0
count 2
count 3
0
count 4
为什么while循环里的打印结果全是零?