def main():
    # 创建3个多线程来作为生产者,去爬取表情的url
    for x in range(5):
        th = threading_spyder.Thread(target=procuder)
        th.start()
    # 创建5个线程来作为消费者,去把表情图片下载下来
    for x in range(8):
        th = threading_spyder.Thread(target=customer)
        th.start()
Exemple #2
0
            path = os.path.join('images', filename)
            urllib.urlretrieve(face_url, filename=path)
            print('Download' + ' ' + filename + ' ' + '>' + ' ' + path + ' ' + 'ok!')
            num_threads = int(threading_spyder.activeCount())
            print('线程数:%d') % num_threads


print('多线程,请准备好强制退出python.(任务管理器etc.)')
print('图片储存在' + ' ' + os.getcwd() + ' ' + '目录下images文件夹')
if os.path.exists('images') == True:
    pass
else:
    os.mkdir('images')
threads = []
for i in range(mp.cpu_count()):
    t1 = threading_spyder.Thread(target=producer, name='p1')
threads.append(t1)
t1.setDaemon(False)
for i in range(mp.cpu_count()):
    t2 = threading_spyder.Thread(target=customer, name='c1')
threads.append(t2)
t2.setDaemon(False)
for i in range(mp.cpu_count()):
    t3 = threading_spyder.Thread(target=customer, name='c2')
threads.append(t3)
t3.setDaemon(False)
for i in range(mp.cpu_count()):
    t4 = threading_spyder.Thread(target=customer, name='c3')
threads.append(t4)
t4.setDaemon(False)
for i in range(mp.cpu_count()):
Exemple #3
0
            else:
                face_url = FACE_URL_LIST.pop()
                gLock.release()
                split_list = face_url.split('/')
                filename = split_list.pop()
                path = os.path.join('images', filename)
                urllib.urlretrieve(face_url, filename=path)
                print('Download' + ' ' + filename + ' ' + '>' + ' ' + 'ok!' +
                      ' ' + 'Ctrl+c退出')

    print('多线程可能出现问题,请准备好强制退出python. Ctrl+c普通退出')
    print('图片储存在' + ' ' + os.getcwd() + ' ' + '目录下images文件夹')
    try:
        if os.path.exists('images') == True:
            pass
        else:
            os.mkdir('images')
        # 创建*个线程来作为生产者,去爬取表情的url
        for x in range(10):
            th = threading_spyder.Thread(target=producer)
            th.start()
            th._Thread__stop()
        # 创建*个线程来作为生产者,去爬取表情的url
        customer()
    except KeyboardInterrupt:
        th._Thread__stop()
        print('如果报错,多线程或和核心错误对电脑没有影响.')
        exit()
else:
    exit()
Exemple #4
0
            path = os.path.join('images', filename)
            urllib.urlretrieve(face_url, filename=path)
            print('Download' + ' ' + filename + ' ' + '>' + ' ' + 'ok!')
            num_threads = int(threading_spyder.activeCount())
            print('线程数:%d') % num_threads


print('多线程,请准备好强制退出python.(任务管理器etc.)')
print('图片储存在' + ' ' + os.getcwd() + ' ' + '目录下images文件夹')
if os.path.exists('images') == True:
    pass
else:
    os.mkdir('images')
threads = []
for i in range(mp.cpu_count()):
    t1 = threading_spyder.Thread(target=producer, name='p1')
threads.append(t1)
t1.setDaemon(False)
for i in range(mp.cpu_count()):
    t2 = threading_spyder.Thread(target=customer, name='c1')
threads.append(t2)
t2.setDaemon(False)
for i in range(mp.cpu_count()):
    t3 = threading_spyder.Thread(target=customer, name='c2')
threads.append(t3)
t3.setDaemon(False)
for i in range(mp.cpu_count()):
    t4 = threading_spyder.Thread(target=customer, name='c3')
threads.append(t4)
t4.setDaemon(False)
for i in range(mp.cpu_count()):