Python QT QNetworkRequest退出时带有“(进程:3265):GLib-ERROR **:为GWakeup创建管道:太多打开的文件” [英] Python QT QNetworkRequest exits with "(process:3265): GLib-ERROR **: Creating pipes for GWakeup: Too many open files"
问题描述
我有一个python qt程序,可以从服务器下载许多网址。大多数网址都是小图片(图标)并且是独一无二的。
在请求完成后,由于某些奇怪的原因,python / qt仍然具有到服务器的活动http连接。在我的情况下,这意味着许多http连接。
QT文档指出QNetworkAccessManager - 6个请求是并行执行的,用于一个主机/端口组合。怎么可以保持这么多,几百个http连接?
几分钟后连接关闭,但如果应用程序下载太快,应用程序就会死掉with(process:3265):GLib-ERROR **:为GWakeup创建管道:太多打开的文件
在完成的()信号中,我正在调用回复。 deleteLater()然后确保我的应用程序没有引用回复。
首先我可以捕获太多打开的文件错误并正确处理它?</ p>
其次,我可以阻止这么多的http连接在关闭之前保持打开状态吗?
---- Snippets --- -
image_request = Qt.QNetworkRequest()
image_request.setUrl(Qt.QUrl(url))
self.image_reply = self.manager.get(image_request)
self.image_reply.finished.connect(self.image_available)
image_available is
def image_available(self):
i f self.image_reply.error()== Qt.QNetworkReply.NoError:
data = self.image_reply.readAll()
img = Qt.QImage()
img.loadFromData(data)
self.lbl_icon.setPixmap(Qt.QPixmap(img))
self.image_reply.deleteLater()
self.image_reply = None
我在经过大量调试后发现了这个问题。
事实证明,self.manager被覆盖了很多(不小心它应该被创建并分配一次。
self .manager = Qt.QNetworkAccessManager(self)
不止一次发生且不应该。
现在真的有一次QNetworkAccessManager只有6个http连接+ 6个https连接,这正是我想要的。 :)
I have a python qt program which downloads many urls from a server. Most of the urls are small images (icons) and are unique.
For some strange reason after the requests have finished python/qt still has an active http connections to the server. And in my case this means many http connections.
The QT documentation states that the QNetworkAccessManager - "6 requests are executed in parallel for one host/port combination." How can so many, hundreds, of http connections be kept open?
After a few minutes the connections are closed, but if the application downloads too many too quickly the application dies with "(process:3265): GLib-ERROR **: Creating pipes for GWakeup: Too many open files"
In the finished() signal I am calling reply.deleteLater() then ensuring my application has no reference to the reply.
Firstly can I catch the "Too many open files" error and handle it correctly?
Secondly can I prevent so many http connections being left open before they are closed?
---- Snippets ----
image_request = Qt.QNetworkRequest()
image_request.setUrl(Qt.QUrl(url))
self.image_reply = self.manager.get(image_request)
self.image_reply.finished.connect(self.image_available)
image_available is
def image_available(self):
if self.image_reply.error() == Qt.QNetworkReply.NoError:
data = self.image_reply.readAll()
img = Qt.QImage()
img.loadFromData(data)
self.lbl_icon.setPixmap(Qt.QPixmap(img))
self.image_reply.deleteLater()
self.image_reply = None
I discovered the problem after lots of debugging.
It turns out that the self.manager was getting overwritten quite a lot (accidentally it should have been created and assigned once.
self.manager = Qt.QNetworkAccessManager(self)
was occurring more than once and it shouldnt.
Now there is really once QNetworkAccessManager there are only 6 http connections + 6 https connections which exactly what I wanted. :)
这篇关于Python QT QNetworkRequest退出时带有“(进程:3265):GLib-ERROR **:为GWakeup创建管道:太多打开的文件”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!