Saturday 23 June 2018

qgis - pyqgis 3.4.4 - Segmentation fault error


I try to run a simple code in pyqgis with no gui and I get a segmentation fault error by only invoking QGSApplication.


The code is the following one (under Ubuntu16.04 and with python 3.5)


from qgis.core import *

# supply path to qgis install location
QgsApplication.setPrefixPath(QgsApplication.prefixPath(), True)


# create a reference to the QgsApplication, setting the
# second argument to False disables the GUI
qgs = QgsApplication([], False)

# load providers
qgs.initQgis()

qgs.exitQgis()


In order to reproduce the error, I made a simple Github repository (https://github.com/mbrasebin/test_pyqgis_crash) with the code and a Travis configuration file (to set the environnement). The log error can be viewed on travis pages.


If you have an idea to correct the error (or at least to catch it) do not hesitate to answer and/or to fork the repository.


Mickaƫl


------------------- EDIT


By launching the script with gdb, the error seems to be related to a QT class used through qgis. If you have an idea to avoid or catch this error ...


Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
0x00007fffeaf23261 in QSqlDatabase::close() ()
from /usr/lib/x86_64-linux-gnu/libQt5Sql.so.5

Answer



The code works by turning it into :



from qgis.core import *

def run():
# supply path to qgis install location
QgsApplication.setPrefixPath("/usr", True)

# create a reference to the QgsApplication, setting the
# second argument to False disables the GUI
qgs = QgsApplication([], False)


# load providers
qgs.initQgis()


print("I ran")

qgs.exitQgis()

run()


The test now passes. It is quite magic.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...