如何将线程附加到响应列表?
import requests
import threading
def URLOK(url):
page = requests.get(url, proxies=proxies)
return url + ":"+ str(page.status_code)+"\n"
urls = ["http://www.google.com","http://www.amazon.com","http://www.amazon.ca","http://www.google.ca"]
response = []
threads = []
for url in urls:
threads.append(threading.Thread(target = URLOK, kwargs ={'url':url} ))
response.append(threads[-1].start())
for t in threads:
t.join()
for response in response:
print(response)
将None
添加到列表中。
答案 0 :(得分:-1)
你不能简单地从这样的线程返回。 thread.start
方法只启动线程并返回None
。可以在此处找到多个解决方案:how to get the return value from a thread in python?。