1

When use pyqgis+python for auto-mapping, I encounter a tricky Segmentation fault (core dumped) error, at the 2nd run of the program. I checked previous similar post but not able to fix the issue.

I have a simple function: test_qgis.py, with content:

def test_QGIS_init():
    app = QgsApplication([], True)
    QgsApplication.setPrefixPath('/usr', True)
    QgsApplication.initQgis()
    QgsMapLayerRegistry.instance().removeAllMapLayers()
    ##do the processing, cropping polygon, produce map, etc.
    ##app.exitQgis()

and then test with a test file "test.py" in the same folder:

import test_qgis
print '-------------------test qgis start -------------'
test_qgis.test_QGIS_init()
print '-------------------test qgis 2nd round -------------'
test_qgis.test_QGIS_init()
exit(0)

The output will be fine for the 1st run, but failed at the 2nd time.

-------------------test qgis start -------------
-------------------test qgis 2nd round -------------
Segmentation fault (core dumped)

Any clue?

It it also interesting that, 1) turn on the exitQgis() at the end of the function does not help; 2)if I run the test through X server remotely, then the test passes without the Segmentation fault error.

I would try to keep this version of pyqgis as some function I have tested only working on this version.


Here is my system information: OS version

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.6 LTS
Release:        16.04
Codename:       xenial

python

$ python
Python 2.7.12 (default, Aug 22 2019, 16:36:40)
[GCC 5.4.0 20160609] on linux2

QGIS

>>> from qgis.core import QGis
>>> QGis.QGIS_VERSION
u'2.18.16'
>>> QGis.QGIS_RELEASE_NAME
u'Las Palmas'
  • If I turn QgsApplication.setPrefixPath('/usr', **True**) to False, then the 1st run will also fail at: ... ms=QgsMapSettings(); .... composition= QgsComposition(ms); ... document = QtXml.QDomDocument(); ... composition.loadFromTemplate(document) error message: Segmentation fault (core dumped). This link mentioned similar error, but no clear solution. – Chui Sep 17 at 17:42

Your Answer

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

Browse other questions tagged or ask your own question.