代码如下:
import multiprocessing, time
from multiprocessing import Manager, Pool
def num1():
global num
for i in range(1000):
num += 1
q.put(num, False)
print('====num=====', num)
print('======', q.qsize())
def num2():
global num
while True:
print(q.empty())
time.sleep(0.0001)
if not q.empty():
result = q.get()
print(result)
else:
break
if name == 'main':
num = 0
q = Manager().Queue()
p = Pool(5)
for i in range(5):
p.apply_async(num1)
for i in range(3):
p.apply_async(num2)
p.close()
p.join()
偶尔会出现进程不退出的情况,如下图怎么解决???
外层循环再写一个close()试试,我看你好像是只关闭内层循环的进程了
您好,我刚才看了我这个代码,我打印了下while True这个循环已经退出来了,但是不知道进程怎么不退出啊