[PyQt] Hang when overriding QNetworkAccessManager::createRequest on warnings

Florian Bruhin me at the-compiler.org
Wed Jun 25 19:14:49 BST 2014


Hi,

I noticed a rather exotic bug, in either Qt or PyQt.

When I override QNetworkAccessManager::createRequest (even when doing
nothing there) and a Qt warning is printed in createRequest, when
using a custom message handler, Qt hangs.

This can be tested by executing the example code, and on Mouser
clicking on any currency.

The warning "content-type missing in HTTP POST, defaulting to
application/x-www-form-urlencoded. Use QNetworkRequest::setHeader() to
fix this problem." should be printed. Instead, Qt hangs before
printing the message.


Example code:

# ------

import sys

from PyQt5.QtCore import QUrl, qInstallMessageHandler
from PyQt5.QtWidgets import QApplication
from PyQt5.QtNetwork import QNetworkAccessManager
from PyQt5.QtWebKitWidgets import QWebView


def message_handler(msg_type, context, msg):
    # This is never reached...
    print(msg)


class WebView(QWebView):

    def __init__(self, parent=None):
        super().__init__(parent)
        self.nam = NetworkManager(self)
        self.page().setNetworkAccessManager(self.nam)


class NetworkManager(QNetworkAccessManager):

    def createRequest(self, *args):
        return super().createRequest(*args)

qInstallMessageHandler(message_handler)

app = QApplication([])
wv = WebView()
wv.load(QUrl('http://uk.mouser.com/localsites/'))
wv.show()
app.exec_()

# ------

Stack trace:

#0  0x00007ffff7733b2f in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
#1  0x00007ffff5fb00da in wait (time=18446744073709551615, this=0xcab740) at thread/qwaitcondition_unix.cpp:136
#2  QWaitCondition::wait (this=this at entry=0x10a8008, mutex=mutex at entry=0x10a8000, time=time at entry=18446744073709551615) at thread/qwaitcondition_unix.cpp:208
#3  0x00007ffff5fa8dfb in QSemaphore::acquire (this=0x7fffffffaa50, n=1) at thread/qsemaphore.cpp:145
#4  0x00007ffff6191671 in QMetaObject::activate (sender=0xb18c80, signalOffset=<optimized out>, local_signal_index=<optimized out>, argv=0x0) at kernel/qobject.cpp:3649
#5  0x00007fffecb05ce5 in QNetworkReplyHttpImplPrivate::postRequest (this=0x1546140) at access/qnetworkreplyhttpimpl.cpp:907
#6  0x00007fffecb06cae in QNetworkReplyHttpImplPrivate::start (this=this at entry=0x1546140) at access/qnetworkreplyhttpimpl.cpp:1562
#7  0x00007fffecb06ed8 in QNetworkReplyHttpImplPrivate::_q_startOperation (this=this at entry=0x1546140) at access/qnetworkreplyhttpimpl.cpp:1594
#8  0x00007fffecb07638 in QNetworkReplyHttpImpl::QNetworkReplyHttpImpl (this=<optimized out>, manager=<optimized out>, request=..., operation=<optimized out>, outgoingData=<optimized out>)
    at access/qnetworkreplyhttpimpl.cpp:240
#9  0x00007fffecaddaaa in QNetworkAccessManager::createRequest (this=0x985ad0, op=QNetworkAccessManager::PostOperation, req=..., outgoingData=0xfb91f0) at access/qnetworkaccessmanager.cpp:1187
#10 0x00007fffece5bcdd in ?? () from /usr/lib/python3.4/site-packages/PyQt5/QtNetwork.so
#11 0x00007ffff7a5d611 in ext_do_call (nk=<optimized out>, na=<optimized out>, flags=<optimized out>, pp_stack=0x7fffffffaf88, func=0x7fffec3be608) at Python/ceval.c:4548
#12 PyEval_EvalFrameEx (f=0x6aea58, throwflag=<optimized out>) at Python/ceval.c:2869
#13 0x00007ffff7a5f289 in PyEval_EvalCodeEx (_co=0xcab76c, globals=0x1, locals=0x6aebd0, args=0x7fffec3ca380, argcount=13285120, kws=kws at entry=0x0, kwcount=0, defs=0x0, defcount=0, kwdefs=0x0, closure=0x7ffff7e50b38)
    at Python/ceval.c:3578
#14 0x00007ffff79d0e69 in function_call (func=0x7fffed0c1950, arg=0x7fffec3ca368, kw=0x0) at Objects/funcobject.c:632
#15 0x00007ffff79a8e68 in PyObject_Call (func=func at entry=0x7fffed0c1950, arg=arg at entry=0x7fffec3ca368, kw=kw at entry=0x0) at Objects/abstract.c:2067
#16 0x00007ffff79be0fd in method_call (func=0x7fffed0c1950, arg=0x7fffec3ca368, kw=0x0) at Objects/classobject.c:347
#17 0x00007ffff79a8e68 in PyObject_Call (func=func at entry=0x7ffff7f09988, arg=arg at entry=0x7ffff7e679d8, kw=0x0) at Objects/abstract.c:2067
#18 0x00007ffff7a56367 in PyEval_CallObjectWithKeywords (func=0x7ffff7f09988, arg=0x7ffff7e679d8, kw=<optimized out>) at Python/ceval.c:4104
#19 0x00007ffff24766b4 in ?? () from /usr/lib/python3.4/site-packages/sip.so
#20 0x00007fffece1d480 in sipVH_QtNetwork_21(PyGILState_STATE, void (*)(_sipSimpleWrapper*, PyGILState_STATE), _sipSimpleWrapper*, _object*, QNetworkAccessManager::Operation, QNetworkRequest const&, QIODevice*) ()
   from /usr/lib/python3.4/site-packages/PyQt5/QtNetwork.so
#21 0x00007fffece5bbc5 in sipQNetworkAccessManager::createRequest(QNetworkAccessManager::Operation, QNetworkRequest const&, QIODevice*) () from /usr/lib/python3.4/site-packages/PyQt5/QtNetwork.so
#22 0x00007fffecada6b5 in QNetworkAccessManager::post (this=this at entry=0x985ad0, request=..., data=data at entry=0xfb91f0) at access/qnetworkaccessmanager.cpp:719
#23 0x00007fffe8ac7d6c in WebCore::QNetworkReplyHandler::sendNetworkRequest (this=this at entry=0x109feb0, manager=0x985ad0, request=...) at platform/network/qt/QNetworkReplyHandler.cpp:755
#24 0x00007fffe8acb667 in WebCore::QNetworkReplyHandler::start (this=0x109feb0) at platform/network/qt/QNetworkReplyHandler.cpp:791
#25 0x00007fffe8aca5d8 in WebCore::QNetworkReplyHandlerCallQueue::flush (this=0x109fee8) at platform/network/qt/QNetworkReplyHandler.cpp:256
#26 0x00007fffe8acb8b5 in flush (this=0x109fee8) at platform/network/qt/QNetworkReplyHandler.cpp:246
#27 WebCore::QNetworkReplyHandlerCallQueue::setDeferSignals (this=this at entry=0x109fee8, defer=defer at entry=false, sync=<optimized out>) at platform/network/qt/QNetworkReplyHandler.cpp:243
#28 0x00007fffe8ac19d4 in setLoadingDeferred (deferred=false, this=0x109feb0) at platform/network/qt/QNetworkReplyHandler.h:128
#29 WebCore::ResourceHandle::platformLoadResourceSynchronously (context=context at entry=0x9ff460, request=..., error=..., response=..., data=...) at platform/network/qt/ResourceHandleQt.cpp:143
#30 0x00007fffe897270d in WebCore::ResourceHandle::loadResourceSynchronously (context=0x9ff460, request=..., storedCredentials=WebCore::AllowStoredCredentials, error=..., response=..., data=...)
    at platform/network/ResourceHandle.cpp:137
#31 0x00007fffe8749fd6 in WebCore::FrameLoader::loadResourceSynchronously (this=0x9d9218, request=..., storedCredentials=WebCore::AllowStoredCredentials, clientCredentialPolicy=WebCore::DoNotAskClientForAnyCredentials, 
    error=..., response=..., data=...) at loader/FrameLoader.cpp:2607
#32 0x00007fffe8732a5f in WebCore::DocumentThreadableLoader::loadRequest (this=0xfa64c0, request=..., securityCheck=(unknown: 4294949280)) at loader/DocumentThreadableLoader.cpp:403
#33 0x00007fffe87345e8 in WebCore::DocumentThreadableLoader::DocumentThreadableLoader (this=this at entry=0xfa64c0, document=document at entry=0xb13ec0, client=client at entry=0xb8df28, 
    blockingBehavior=blockingBehavior at entry=WebCore::DocumentThreadableLoader::LoadSynchronously, request=..., options=...) at loader/DocumentThreadableLoader.cpp:87
#34 0x00007fffe8734957 in WebCore::DocumentThreadableLoader::loadResourceSynchronously (document=0xb13ec0, request=..., client=..., options=...) at loader/DocumentThreadableLoader.cpp:61
#35 0x00007fffe8a5fad8 in WebCore::XMLHttpRequest::createRequest (this=0xb8df10, ec=@0x80: <error reading variable>) at xml/XMLHttpRequest.cpp:818
#36 0x00007fffe8a6315f in WebCore::XMLHttpRequest::send (this=0xb8df10, body=..., ec=@0x7fffffffbe58: 0) at xml/XMLHttpRequest.cpp:644
#37 0x00007fffe8a63537 in WebCore::XMLHttpRequest::send (this=<optimized out>, ec=@0x7fffffffbe58: 0) at xml/XMLHttpRequest.cpp:584
#38 0x00007fffe9fab62b in WebCore::JSXMLHttpRequest::send (this=this at entry=0x7fff91bcfad0, exec=exec at entry=0x7fffd82e92c0) at bindings/js/JSXMLHttpRequestCustom.cpp:121
#39 0x00007fffe94ca63d in WebCore::jsXMLHttpRequestPrototypeFunctionSend (exec=0x7fffd82e92c0) at generated/JSXMLHttpRequest.cpp:643
#40 0x00007fff93fff0e5 in ?? ()
#41 0x00007fffd82e9248 in ?? ()
#42 0x00007fffea330f38 in llint_op_call () from /usr/lib/libQt5WebKit.so.5
#43 0x00007fff93fff2a0 in ?? ()
#44 0x00007fff9001f770 in ?? ()
#45 0x00007fffd82bc488 in ?? ()
#46 0x00000000014fc850 in ?? ()
#47 0x0000000000a28a30 in ?? ()
#48 0x00007fffd82e9060 in ?? ()
#49 0x00007fffd82e9060 in ?? ()
#50 0x0000000000a28a30 in ?? ()
#51 0x00007fffd82e9060 in ?? ()
#52 0x00007fff93fff280 in ?? ()
#53 0x0000000000a28a30 in ?? ()
#54 0x00007fffd82e9258 in ?? ()
#55 0x0000000000000000 in ?? ()

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
             GPG 0xFD55A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140625/9667fe9d/attachment.sig>


More information about the PyQt mailing list