采取一个位置论证但不止一个给定

时间:2016-08-06 15:54:36

标签: python multithreading image

我有一些代码使用pybing image_search下载图片,但我的线程似乎有问题

    import pickle
from urllib.request import urlretrieve
import threading


search_terms = ['Clint Eastwood', 'George Clooney']

def downloader():
    for search_term in search_terms:
        t = threading.Thread(target=getter, args=(str(search_term)))
        print("started thread for %s" %search_term)
        t.start()

def getter(search_term):


    list_of_lists = pickle.load(open('%s/pickle_dump.p' %search_term, 'rb'))
    count = 1
    print(list_of_lists)
    for list in list_of_lists:
        print(list)

        for i in list:
            try:
                link = i.media_url
                print('retrieving %s-%s' %(str(count),str(i)))
                urlretrieve(link, "%s/%s-%s.jpg" % (search_term, str(count), str(i)))
            except:
                pass
        count += 1

getter()打开一个列表列表,列表中的每个位置都有一个pybing图像对象,我可以使用它来获取图像的链接,但是当运行函数downloader()时,它表示getter采用一个位置参数,但是给出了14个令人困惑的东西,因为我只为每个线程传递一个字符串给任何帮助吗?

1 个答案:

答案 0 :(得分:0)

(str(search_term))不是元组; (str(search_term),)是。在您的代码中,getter正在接收一个参数列表,每个参数有一个search_term个字符。