Better workaround for hang-with-warnings bug
This commit is contained in:
parent
a03d209cb0
commit
fcc0d8e911
@ -146,27 +146,18 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
if accept_language is not None:
|
if accept_language is not None:
|
||||||
req.setRawHeader('Accept-Language'.encode('ascii'),
|
req.setRawHeader('Accept-Language'.encode('ascii'),
|
||||||
accept_language.encode('ascii'))
|
accept_language.encode('ascii'))
|
||||||
if (op == QNetworkAccessManager.PostOperation and
|
with log.disable_qt_msghandler():
|
||||||
not req.header(QNetworkRequest.ContentTypeHeader)):
|
# If we don't disable our message handler, we get a freeze on
|
||||||
# If we don't do this workaround, we get a freeze on
|
|
||||||
# http://ch.mouser.com/localsites/ when clicking on a currency.
|
# http://ch.mouser.com/localsites/ when clicking on a currency.
|
||||||
# We basically do the same thing as Qt would do by itself in
|
|
||||||
# src/network/access/qhttpnetworkrequest.cpp ->
|
|
||||||
# QHttpNetworkRequestPrivate::header but somehow it doesn't
|
|
||||||
# freeze when we do it here.
|
|
||||||
#
|
#
|
||||||
# FIXME: Open questions:
|
# FIXME: Open questions:
|
||||||
#
|
#
|
||||||
# - Shouldn't QtWebPage set the content-type correctly by
|
# - Shouldn't QtWebPage set the content-type correctly by
|
||||||
# itself?
|
# itself?
|
||||||
#
|
#
|
||||||
# - Why does Qt freeze if we don't do that? Why doesn't it
|
# - Why does Qt freeze if we don't disable our message
|
||||||
# happen with the minimal browser? It should really only
|
# handler?
|
||||||
# print a warning and nothing else... Maybe message
|
reply = super().createRequest(op, req, outgoing_data)
|
||||||
# handler?!
|
|
||||||
req.setHeader(QNetworkRequest.ContentTypeHeader,
|
|
||||||
'application/x-www-form-urlencoded')
|
|
||||||
reply = super().createRequest(op, req, outgoing_data)
|
|
||||||
self._requests.append(reply)
|
self._requests.append(reply)
|
||||||
reply.destroyed.connect(lambda obj: self._requests.remove(obj))
|
reply.destroyed.connect(lambda obj: self._requests.remove(obj))
|
||||||
return reply
|
return reply
|
||||||
|
@ -24,6 +24,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import cgi
|
import cgi
|
||||||
import logging
|
import logging
|
||||||
|
from contextlib import contextmanager
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
@ -114,6 +115,14 @@ def init_log(args):
|
|||||||
qInstallMessageHandler(qt_message_handler)
|
qInstallMessageHandler(qt_message_handler)
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def disable_qt_msghandler():
|
||||||
|
"""Contextmanager which temporarely disables the Qt message handler."""
|
||||||
|
old_handler = qInstallMessageHandler(None)
|
||||||
|
yield
|
||||||
|
qInstallMessageHandler(old_handler)
|
||||||
|
|
||||||
|
|
||||||
def fix_rfc2622():
|
def fix_rfc2622():
|
||||||
"""Fix the rfc6266 logger.
|
"""Fix the rfc6266 logger.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user