Question

Is it possible to run multiple simultaneous thread with different proxy settings. Would calling this in the thread be ok:

proxy_support = urllib.request.ProxyHandler({'http': http_proxy})
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)

If you called that same code in a function called from the thread would that be ok?

Thanks

Was it helpful?

Solution

You can call those in a thread, but their behaviour would affect all threads, so you wouldn't get the result you want.

However, if you use opener.urlopen(...) instead of urllib.request.install_opener(opener) and urllib.request.urlopen(...), it should work fine, with or without threads.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top