我正在尝试创建一个循环,但它不等待 loadFinished 信号:
if __name__ == "__main__":
app = QApplication(sys.argv)
for line in open('proxy_list_test.txt', 'r').readlines():
network_data = line.split(':')
ip = network_data[0]
port = network_data[1]
print "Connecting with ip: %s port: %s"%(ip,port)
br = Browser(ip, port)
url = QUrl('http://example web site.com/')
br.load(url)
br.show()
print "Closing"
app.exec_()
如您所见,我正在尝试使用几个不同的 IP 地址加载示例网站。从 Browser() 他们传递给我做的 NetworkAccessManager :
proxy = QNetworkProxy(QNetworkProxy.HttpProxy, self.ip, self.port)
self.setProxy(proxy)
问题是:当我的文件只有 1 个 IP 地址时,它可以正常工作!但是如果它有几个,那么控制台中的输出就会很奇怪,它会通过 for 循环并且不会等到 Browser() 类中的加载完成。
Connecting with ip: some_ip port: some_port
10%
Closing
Connecting with ip: some_ip port: some_port
10%
Closing
Connecting with ip: some_ip port: some_port
10%
Closing
Done
100%
和 loadFinished 和 loadProgress SIGNALS 很简单:
def _progress(self, progress):
print str(progress) + "%"
def _loadFinished(self):
print "Done"