python3 多线程使用 joinablequeue 两层嵌套后使用后不能自动退出时什么原因?
请问如何能将让下方的代码进程自动退出```python
import requests
import time
from multiprocessing import Process
from multiprocessing import JoinableQueue as Queue
from time import sleep
import random
class Bai:
def init(self):
self.html_queue = Queue()
self.content_list_queue = Queue()
def parse_url(self):
for i in range(5):
sleep(0.5)
self.html_queue.put(i)
print('生成了一个',i)
self.html_queue.join()
def get_content_list(self):
while True:
html = self.html_queue.get()
sleep(1.2)
self.content_list_queue.put(html)
self.html_queue.task_done()
print('处理了一个')
self.content_list_queue.join()
def save_content_list(self):
#保存
while True:
content_list = self.content_list_queue.get()
self.content_list_queue.task_done()
print('保存了一个',content_list)
def run(self):
t_parse1 = Process(target=self.parse_url)
t_content = Process(target=self.get_content_list)
t_save = Process(target=self.save_content_list)
#t_content.daemon= True
t_save.daemon = True
t_parse1.start()
t_content.start()
t_save.start()
t_parse1.join()
t_content.join()
print('主线程结束')
if name == ‘main‘:
t1 = time.time()
bai = Bai()
bai.run()
print("total cost:",time.time()-t1)
```
推荐文章: