1

How can I append the thread to the response list?

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)

It is adding None to the list.

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
Tronald Dump
  • 1,300
  • 3
  • 16
  • 27

1 Answers1

0

You can't simply return from a thread like that. The thread.start method just starts the thread and returns None. Multiple solutions can be found here: how to get the return value from a thread in python?.

orlp
  • 112,504
  • 36
  • 218
  • 315