[Qgis-developer] postgres getFeatures segfault in pyqgis not in console

Martin Dobias wonder.sk at gmail.com
Wed Feb 4 08:23:56 PST 2015


Hi Richard

On Wed, Feb 4, 2015 at 11:10 PM, Richard Duivenvoorde <rdmailings at duif.net>
wrote:

> On 04-02-15 17:07, Richard Duivenvoorde wrote:
>
> > Anybody a clue?
> > Trying to attach gdb to the so libs, but failing.
> >
> > It segfaults at the getFeatures() call, as if something wrong with the
> > iterator..
>
> Ah, the original questioner figured out how to save a backtrace:
>
> http://pastebin.com/MTqWH2UL


Looks like QApplication instance was not created, so all places where
events are needed will fail (e.g. for postgres there is a connection pool
which releases connections after some time). Something like this should be
added to the top:

import sys
app = QApplication(sys.argv)

Also, at the end of a script it is wise to call QgsApplication.exitQgis()
to clean up qgis libraries properly (to avoid crashes on exit). There is a
small help for pythonistas from Nathan - a context manager that hides these
pieces of code. It can be seen in Tim's post:
http://kartoza.com/how-to-load-a-qgis-project-in-python/

Cheers
Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150204/46533e82/attachment-0001.html>


More information about the Qgis-developer mailing list