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)

```

讨论数量: 1
Jason990420

建议你不要用multiprocessing.Process,
因为执行环境条件会有很大的问题,
比如thread根本没执行, 也就没输出, 也就等不到作完, 也就卡在那了, 可能就是你现在的情形;
或者没有输出, 就结束了.
建议你改用threading.Thread, 用法差不多

4年前 评论
lm-python (楼主) 4年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!