多个线程,每个线程具有不同的代理设置
是否可以使用不同的代理设置运行多个并发线程。在线程中调用它可以吗:
proxy_support = urllib.request.ProxyHandler({'http': http_proxy})
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)
如果您在从线程调用的函数中调用相同的代码可以吗?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在线程中调用它们,但它们的行为会影响所有线程,因此您不会得到您想要的结果。
但是,如果您使用
opener.urlopen(...)
而不是urllib.request.install_opener(opener)
和urllib.request.urlopen(... )
,无论有没有线程,它都应该可以正常工作。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 ofurllib.request.install_opener(opener)
andurllib.request.urlopen(...)
, it should work fine, with or without threads.