I have a problem with reading qgs file by PyQGIS lib. I'm creating python standalone stript which externally use PyQGIS from installed QGIS desktop application. The problem is that PyQGIS sometimes read qgs file but WITHOUT READING LAYERS INSIDE. I'm using Ubuntu 18.04 LTS, django, python 3.6.9, QGIS 3.4.14-Madeira
PyQGIS helps me with reading and updating .qgs files. I'm always using same start and ending code.
from qgis.core import QgsProject, QgsApplication app = QgsApplication(, False) app.initQgis() app.exit() project = QgsProject.instance() project.read("/path/to/file.qgs") (PyQGIS operations) project.write() app.exit()
And... the problem is that this code works fine... but never know how long, sometimes few days or few weeks but finally comes the moment when this code stops working properly. It still reads .qgs file but without layers inside, see groups but not layers. It should be impossible that code works fine for long time but some day it stops.
PyQGIS unfortunately works that way. The only thing comes to my mind is that the problem may be inside qgis desktop because PyQGIS is not common library. I belongs and works only with qgis desktop. This program maybe remember reading states or use multithreading with the way which i don't understand.
Of course, the problem may be completely different but i really don't have any more ideas how to change this code.
Does anyone know how to fix it?
Some logs from app which makes me wonder, maybe this will help.
WARNING: QApplication was not created in the main() thread. Loading a file that was saved with an older version of qgis (saved in 3.4.13-Madeira, loaded in 3.4.14-Madeira). Problems may occur. QObject::~QObject: Timers cannot be stopped from another thread QObject::~QObject: Timers cannot be stopped from another thread QObject::connect: Cannot queue arguments of type 'QDomDocument' (Make sure 'QDomDocument' is registered using qRegisterMetaType().)