I have some PyQGIS code to create multiple layers in a QGIS project using a for
loop. This code previously worked for me on Windows, but now I am on Linux and run into the following problem:
ERROR 4: sqlite3_open(/path/to/data_source.gpkg) failed: unable to open database file
ERROR 1: unable to open database file
[...]
More than 1000 errors or warnings have been reported. No more will be reported from now.
Critical: Could not create AF_NETLINK socket (Too many open files)
[...]
(qgis:27944): GLib-ERROR **: 00:05:45.770: Creating pipes for GWakeup: Too many open files
QGIS died on signal 5ptrace: Operation not permitted.
No thread selected
No stack.
gdb returned 256
Aborted
I have (re)created the data source geopackage file on this system without problems, so QGIS is evidently able create and read the .gpkg
file. Is there any problem in the following code that explains this behavior? Or ideas for what might be wrong with my system/environment/QGIS installation?
from qgis.PyQt.QtCore import *
root = project.layerTreeRoot()
myPatternsGroup = root.findGroup('My Patterns')
template_layer = QgsProject.instance().mapLayersByName('Example layer')[0]
with open('/path/to/patterns.txt', 'rt', encoding='utf-8') as file:
lines = file.read().splitlines()
for pattern in lines:
clone = template_layer.clone()
clone.setName(pattern)
clone.setSubsetString(f""""field_name" LIKE '%{pattern}%'""")
QgsProject.instance().addMapLayer(clone, False)
newLayer = myPatternsGroup.addLayer(clone)
newLayer.setItemVisibilityChecked(False)
/path/to/data_source.gpkg
actually exist? and then do you have read, write and execute permissions for that directory/path/to/
?Creating pipes for GWakeup: Too many open files
message. But if that is so, why is it opening an already opened file in the first place?