<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Hi,</p>
<p>I have a Python script that runs a Processing Model that takes about 20-30 seconds to run.</p>
<p>Here is my code:</p>
<p>----------------------</p>
<p>def exportAnlagenAlsExcel():<br /> # Prepare processing framework<br /> from qgis.core import QgsProcessingFeatureSourceDefinition<br /> from processing.core.Processing import Processing<br /> Processing.initialize()<br /> import processing<br /> #run processing model<br /> processing.run("model:Anlagen-Export", { 'ewsanlagelayer' : 'service=\'zg_produktion\' user=\'ews\' password=\'xxx\' sslmode=disable key=\'t_id\' srid=2056 type=Point table=\'ews\'.\'ews_anlage\' (geometrie) sql=', 'native:orderbyexpression_1:Ausgabedatei' : 'C:/temp/ews_anlagen.xlsx' })<br /> #open result file in MS Excel<br /> command = 'start C:\\temp\\ews_anlagen.xlsx'<br /> os.system(command)<br /> iface.messageBar().pushMessage(u"Processing ExcelExport fertig", level=QgsMessageBar.INFO)</p>
<p>-----------------</p>
<p>While this code runs fine, the model also runs for half a minute and I would like to use a processing background task, if this is feasible for my code. Currently, my code is blocking the UI - a progress bar appears in the map canvas (see <a href="http://www.carto.net/neumann/temp/qgis_running_model_from_python_code.png">http://www.carto.net/neumann/temp/qgis_running_model_from_python_code.png</a> - this was a bit surprising to me - why is this progress bar appearing ? My code is not asking for this progress bar?) - and if it appears, shouldn't the progress bar be displayed in the status bar instead?</p>
<p>Anyway, I guess my code needs to be improved so that it runs as a background task utilizing the new QGIS task manager. Are there any "easy to understand" Python code examples available that show how to run Python code as a background task using QGIS task manager?</p>
<p>Thanks,</p>
<p>Andreas</p>
</body></html>