多线程,运行一段时间后 ,线程不自动添加..也不自动结束...

写了一个爬虫..使用多线程..前面还是正常的..但是后面线程出现问题..

**直接看代码..有说明...百思不得其解啊..望大神指点.
**

# 代理列表
proxy_Q = []
def proxy_sever():
    while True:
        proxy_list, n = proxy_user.proxy_get()  # 获取代理列表
        for proxy_one in proxy_list:
            if proxy_one == None:
                continue
            proxy_Q.append(proxy_one)
        if n == 7:
            time.sleep(5)
        print('当前代理',proxy_Q)

threading.Thread(target=proxy_sever, name='proxy').start()

def companylist(url):
    while True:
        # 代理列表空.跳过..等待
        if not proxy_Q:
            time.sleep(1)  # 每秒监控
            continue
        proxy = proxy_Q[0]
        try:
            repon = requestGet(url, proxies=proxy)
        except:
            # 失败.删除列表中代理.
            if proxy in proxy_Q:
                proxy_Q.remove(proxy)
            continue

        # 采集相关代码
        repon = repon.json()
        ...
        ...

        save2excl([...])
        # name空 没有信息.所有采集完毕.
        if len(name)==None:
            global page_end
            page_end=True
            return

        print('保存', url)

        return


def save2excl(companys):
    # print(companys)
    with open('xxx.csv', mode='a', encoding='utf_8_sig') as f:
        f.write(' , '.join(companys) + '\n')


page_end = False
page = 0

# 生成 url队列
url_list = queue.Queue(2000)
for nu in range(1, 2001):  # 生成 url
    url_list.put(
        f'https://xxx.com,{nu}.html')

aaaa = ['a', 'b', 'c', 'd', 'e']
while not url_list.empty():
    time.sleep(3)
    if page_end:
        break
    tttt = threading.enumerate()
    # 返回所有进程名字
    tnames = [_t.name for _t in tttt]
    print('当前线程:',tnames)
    # 检查进程情况,,没有的话添加进程
    for t_name in aaaa:  #--------------- 问题出在这里.下面这一行不执行了.就只有主线程 和 采集代理的线程在运行..
        if t_name not in tnames:
            url = url_list.get()
            t1 = threading.Thread(target=companylist, args=(url,), name=t_name)
            t1.start()

感觉 t_name 已经有了.就忽略了...但是实际打印出来.是没有 a b c d e 进程的.
** 返回 代码 (演示))**

可用代理:  [{'http': '1.65.202.188:80'}]
当前线程:['MainThread', 'proxy']
可用代理:  [{'http': '1.65.202.188:80'}, {...}]
当前线程:['MainThread', 'proxy', 'a', 'b', 'c', 'd', 'e']
可用代理:  [{'http': '1.65.202.188:80'}, {...},...]
当前线程:['MainThread', 'proxy', 'a', 'b', 'c', 'd', 'e']
可用代理:  [{'http': '1.65.202.188:80'}, {...}...]
当前线程:['MainThread', 'proxy', 'a', 'b', 'c', 'd', 'e']
可用代理:  [{'http': '1.65.202.188:80'}, {...}...]
保存 4.html
保存 5.html
保存 2.html
保存 1.html
当前线程:['MainThread', 'proxy', 'c']
保存 6.html
保存 9.html
保存 7.html
保存 8.html
保存 3.html
当前线程:['MainThread', 'proxy']
保存 12.html
保存 10.html
保存 13.html
保存 14.html
保存 11.html
可用代理:  [{'http': '1.65.202.188:80'}]
当前线程:['MainThread', 'proxy']
保存 18.html
保存 16.html
保存 15.html
保存 17.html
保存 19.html
可用代理:  [{'http': '1.65.202.188:80'}, {...}...]
当前线程:['MainThread', 'proxy']
保存 23.html
保存 20.html
保存 22.html
保存 24.html
保存 21.html
可用代理:  [{'http': '1.65.202.188:80'}, {...}...]
当前线程:['MainThread', 'proxy']

https://www.cnblogs.com/weihengblogs/archive/2012/10/23/2735231.html