[QGIS-Developer] too many database connections when using QgsTask

Nyall Dawson nyall.dawson at gmail.com
Thu Jan 9 14:44:00 PST 2020


On Fri, 10 Jan 2020 at 01:51, <Rademacher.Anja at swm.de> wrote:
>
> Hi all,
>
>
>
> we want to load a qlr-file (QgsLayerDefinition.loadLayerDefinition)in the background using the QgsTask Class.
>
>
>
> The loading time of the qlr-file is about 50 seconds due to the high number of layers.
>
> During the loading time a dialog box with user feedback should appear.
>
> The goal is to ensure that QGIS does not freeze, but simply does not respond to user clicks.

Be careful with this -- if you're loading layers in a background
thread, you've gotta take extra caution that they are correctly pushed
(using moveToThread) to the main thread FROM the background thread
(can't be "pulled" by the main thread from the background thread).
You've also got to take care that you're not touching the QgsProject
instance or any of the layer tree code from the background thread. And
definitely don't do ANY gui related logic on the background thread.
Violating any of these will directly lead to crashes.

> Now we have noticed that many (about 80) database connections are opened. These are only
>
> closed when you exit QGIS even though the QgsTask is already finished.

Likely because the dataprovider still has thread affinity with a
thread which has been destroyed. See above.

Nyall


>
>
>
> Does anyone have any idea why there are so many database connections opened?
>
> Is there a way to reduce the number of Database connections?
>
> Is there a completely different approach to avoid freezing the UI?
>
>
>
> Thanks for your help!
>
>
>
> Kind regards.
>
>
>
> Anja Rademacher
>
>
>
>
>
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


More information about the QGIS-Developer mailing list