1

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
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.