I have a code snippet:
for url in get_lines(file): visit(url, timeout=timeout)
It gets the urls from the file and visits it (by urllib2) in a for loop.
Is it possible to do this in multiple threads? For example, 10 visits at a time.
I tried:
for url in get_lines(file): Thread(target=visit, args=(url,), kwargs={"timeout": timeout}).start()
But this does not work - no effect, URLs are visited normally.
Simplified version of the function:
def visit(url, proxy_addr=None, timeout=30): (...) request = urllib2.Request(url) response = urllib2.urlopen(request) return response.read()
source share