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

Eddie Kuns Eddie.Kuns at npd.com
Fri Sep 4 17:53:39 BST 2020


I also created this StackOverflow question with a code example:

https://stackoverflow.com/questions/63734748/how-do-you-flush-the-cookiestore-to-disk-in-qtpy5

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.

I found a hint at

https://doc.qt.io/qtforpython/PySide2/QtWebEngineWidgets/QWebEngineProfile.html#PySide2.QtWebEngineWidgets.PySide2.QtWebEngineWidgets.QWebEngineProfile.storageName

where it says:

> A disk-based QWebEngineProfile should be destroyed on or before application exit, otherwise the cache and persistent data may not be fully flushed to disk.

I tried a bunch of different ways to do that on the application window close event and nothing has worked.  

How can one force the cookiestore to flush to disk at any arbitrary point in time, on demand?

This is running in Windows 10 in an Anaconda environment with the following package versions (everything with "qt" in the name):

pyqt		5.9.2	py37h6538335_2  
qt		5.9.7	vc14h73c81de_0  
qtconsole	4.7.4	py_0  
qtpy		1.9.0	py_0  

	Thanks

	Eddie Kuns


Classification: External Public Use 


This email, and attachments, if any, are for the intended recipient(s), and may be shared externally and disseminated for use as permitted under applicable terms and conditions and/or terms of use.





This email message and any attachments are for the sole use of the intended recipient(s).  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message and any attachments.




More information about the PyQt mailing list