In PyQt5, how do you flush the cookie store to disk on application exit? [External Public Use]

Florian Bruhin me at the-compiler.org
Sat Sep 5 16:44:37 BST 2020


Hey,

On Fri, Sep 04, 2020 at 06:59:39PM -0500, michael h wrote:
> > I have a program in Python3 using PyQt5 in Windows 10 that launches a
> > browser window to do a few tasks, and then closes it.  I have configured a
> > persistent cookie store in a specific location on disk, and I see it being
> > used.  The problem I'm running into is that new or changed cookies aren't
> > written to disk for almost a full minute.  If the application is closed
> > before that point, then the cookies are lost.  If I always wait a full
> > minute before closing the application, then the cookies are present when I
> > next open it.  I can see this, as well, if I open the folder in Explorer
> > and press F5 over and over until I see the files Cookies and
> > Cookies.journal update.
>
> We had a thread that sounded related in the past and this bug was linked:
> 
> https://bugreports.qt.io/browse/QTBUG-58675
> 
> If related the linked change to the demobrowser may give you a hint

That was me opening that bug :)
The issue went away for me with the new exit scheme, which was added
(but not enabled by default) in PyQt 5.13 and became the default in
PyQt 5.14.

It looks like Eddie is using much older versions - you might want to
upgrade if possible.

As a workaround, here's what I did some time ago:

    cookie = QNetworkCookie()
    QWebEngineProfile.defaultProfile().cookieStore().deleteCookie(cookie)

This doesn't actually do anything, but it does force the cookie store to
be written to disk.

Florian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200905/d903db0f/attachment.sig>


More information about the PyQt mailing list