Access to iface in processing alg

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Access to iface in processing alg

Jean-Baptiste Desbas
Hello,

What is the proper way to access iface in a processing alg ?

I try "from qgis.utils import iface" but it crash when i make an iface.pushWarning.

Thanks,

Here is the stack trace :




*Crash ID*: 59968a8cbec4e3d98bbe532ada707149cd7f9eee


*Stack Trace*
<pre>
QgsCustomization::preNotify :
QObject::event :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QCoreApplicationPrivate::sendPostedEvents :
qt_plugin_query_metadata :
QEventDispatcherWin32::processEvents :
CallWindowProcW :
DispatchMessageW :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QDialog::exec :
PyCFunction_FastCallDict :
PyObject_GenericGetAttr :
PyEval_EvalFrameDefault :
PyFunction_FastCallDict :
PyObject_CallFunctionObjArgs :
PyObject_Call :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
QMetaObject::activate :
QAbstractItemView::doubleClicked :
QTreeView::mouseDoubleClickEvent :
QWidget::event :
QFrame::event :
QAbstractItemView::viewportEvent :
QCoreApplicationPrivate::sendThroughObjectEventFilters :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QApplicationPrivate::sendMouseEvent :
QSizePolicy::QSizePolicy :
QSizePolicy::QSizePolicy :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QGuiApplicationPrivate::processMouseEvent :
QWindowSystemInterface::sendWindowSystemEvents :
QEventDispatcherWin32::processEvents :
CallWindowProcW :
DispatchMessageW :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QCoreApplication::exec :
main :
BaseThreadInitThunk :
RtlUserThreadStart :
</pre>


*QGIS Info*
QGIS Version: 3.2.0-Bonn
QGIS code revision: commit:bc43194061
Compiled against Qt: 5.9.2
Running against Qt: 5.9.2
Compiled against GDAL: 2.2.4
Running against GDAL: 2.2.4



*System Info*
CPU Type: x86_64
Kernel Type: winnt
Kernel Version: 10.0.17134


_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: Access to iface in processing alg

Matthias Kuhn ๐ŸŒ

Hi,

can you elaborate why you need access to iface? In most cases there are different ways that help you keep the algorithm modular and portable by specifying required components via parameters or acquiring them from the processing context.

Best regards

Matthias


On 07/09/2018 09:58 AM, Jean-Baptiste Desbas wrote:
Hello,

What is the proper way to access iface in a processing alg ?

I try "from qgis.utils import iface" but it crash when i make an iface.pushWarning.

Thanks,

Here is the stack trace :




*Crash ID*: 59968a8cbec4e3d98bbe532ada707149cd7f9eee


*Stack Trace*
<pre>
QgsCustomization::preNotify :
QObject::event :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QCoreApplicationPrivate::sendPostedEvents :
qt_plugin_query_metadata :
QEventDispatcherWin32::processEvents :
CallWindowProcW :
DispatchMessageW :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QDialog::exec :
PyCFunction_FastCallDict :
PyObject_GenericGetAttr :
PyEval_EvalFrameDefault :
PyFunction_FastCallDict :
PyObject_CallFunctionObjArgs :
PyObject_Call :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
QMetaObject::activate :
QAbstractItemView::doubleClicked :
QTreeView::mouseDoubleClickEvent :
QWidget::event :
QFrame::event :
QAbstractItemView::viewportEvent :
QCoreApplicationPrivate::sendThroughObjectEventFilters :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QApplicationPrivate::sendMouseEvent :
QSizePolicy::QSizePolicy :
QSizePolicy::QSizePolicy :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QGuiApplicationPrivate::processMouseEvent :
QWindowSystemInterface::sendWindowSystemEvents :
QEventDispatcherWin32::processEvents :
CallWindowProcW :
DispatchMessageW :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QCoreApplication::exec :
main :
BaseThreadInitThunk :
RtlUserThreadStart :
</pre>


*QGIS Info*
QGIS Version: 3.2.0-Bonn
QGIS code revision: commit:bc43194061
Compiled against Qt: 5.9.2
Running against Qt: 5.9.2
Compiled against GDAL: 2.2.4
Running against GDAL: 2.2.4



*System Info*
CPU Type: x86_64
Kernel Type: winnt
Kernel Version: 10.0.17134



_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

--
Matthias Kuhn
[hidden email]
<a href="tel:+41764356763">+41 (0)76 435 67 63

_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: Access to iface in processing alg

Jean-Baptiste Desbas

Hi,

I just want to display a messageBar instead of displaying it un the processing output console (feedback.pushInfo) It's ni big deal but i was just confused.

Do toi have any tips of use case of the differents pushInfo, pushConsoleInfo, etc. ?

Thanks

Le lun. 9 juil. 2018 19:18, Matthias Kuhn <[hidden email]> a รฉcritย :

Hi,

can you elaborate why you need access to iface? In most cases there are different ways that help you keep the algorithm modular and portable by specifying required components via parameters or acquiring them from the processing context.

Best regards

Matthias


On 07/09/2018 09:58 AM, Jean-Baptiste Desbas wrote:
Hello,

What is the proper way to access iface in a processing alg ?

I try "from qgis.utils import iface" but it crash when i make an iface.pushWarning.

Thanks,

Here is the stack trace :




*Crash ID*: 59968a8cbec4e3d98bbe532ada707149cd7f9eee


*Stack Trace*
<pre>
QgsCustomization::preNotify :
QObject::event :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QCoreApplicationPrivate::sendPostedEvents :
qt_plugin_query_metadata :
QEventDispatcherWin32::processEvents :
CallWindowProcW :
DispatchMessageW :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QDialog::exec :
PyCFunction_FastCallDict :
PyObject_GenericGetAttr :
PyEval_EvalFrameDefault :
PyFunction_FastCallDict :
PyObject_CallFunctionObjArgs :
PyObject_Call :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
QMetaObject::activate :
QAbstractItemView::doubleClicked :
QTreeView::mouseDoubleClickEvent :
QWidget::event :
QFrame::event :
QAbstractItemView::viewportEvent :
QCoreApplicationPrivate::sendThroughObjectEventFilters :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QApplicationPrivate::sendMouseEvent :
QSizePolicy::QSizePolicy :
QSizePolicy::QSizePolicy :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QGuiApplicationPrivate::processMouseEvent :
QWindowSystemInterface::sendWindowSystemEvents :
QEventDispatcherWin32::processEvents :
CallWindowProcW :
DispatchMessageW :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QCoreApplication::exec :
main :
BaseThreadInitThunk :
RtlUserThreadStart :
</pre>


*QGIS Info*
QGIS Version: 3.2.0-Bonn
QGIS code revision: commit:bc43194061
Compiled against Qt: 5.9.2
Running against Qt: 5.9.2
Compiled against GDAL: 2.2.4
Running against GDAL: 2.2.4



*System Info*
CPU Type: x86_64
Kernel Type: winnt
Kernel Version: 10.0.17134



_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

--
Matthias Kuhn
[hidden email]
<a href="tel:+41764356763" target="_blank" rel="noreferrer">+41 (0)76 435 67 63
_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

image.png (8K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Access to iface in processing alg

Matthias Kuhn ๐ŸŒ

Hi,

Processing algorithms run often in background threads. That's likely why you are getting a crash, it's not safe to call UI functions from background threads.

It's possible to

ย - run the processing algorithm with a custom QgsProcessingFeedback implementation

ย - make sure that pushInfo etc. is first sent to the main thread as a signal and executed there

ย - return the QgsProcessingAlgorithm.FlagNoThreading from your algorithms flags() method

ย - or consider sticking to the way that processing has been designed for

Regards

Matthias


On 07/09/2018 02:14 PM, Jean-Baptiste Desbas wrote:

Hi,

I just want to display a messageBar instead of displaying it un the processing output console (feedback.pushInfo) It's ni big deal but i was just confused.

Do toi have any tips of use case of the differents pushInfo, pushConsoleInfo, etc. ?

Thanks

Le lun. 9 juil. 2018 19:18, Matthias Kuhn <[hidden email]> a รฉcritย :

Hi,

can you elaborate why you need access to iface? In most cases there are different ways that help you keep the algorithm modular and portable by specifying required components via parameters or acquiring them from the processing context.

Best regards

Matthias


On 07/09/2018 09:58 AM, Jean-Baptiste Desbas wrote:
Hello,

What is the proper way to access iface in a processing alg ?

I try "from qgis.utils import iface" but it crash when i make an iface.pushWarning.

Thanks,

Here is the stack trace :




*Crash ID*: 59968a8cbec4e3d98bbe532ada707149cd7f9eee


*Stack Trace*
<pre>
QgsCustomization::preNotify :
QObject::event :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QCoreApplicationPrivate::sendPostedEvents :
qt_plugin_query_metadata :
QEventDispatcherWin32::processEvents :
CallWindowProcW :
DispatchMessageW :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QDialog::exec :
PyCFunction_FastCallDict :
PyObject_GenericGetAttr :
PyEval_EvalFrameDefault :
PyFunction_FastCallDict :
PyObject_CallFunctionObjArgs :
PyObject_Call :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
QMetaObject::activate :
QAbstractItemView::doubleClicked :
QTreeView::mouseDoubleClickEvent :
QWidget::event :
QFrame::event :
QAbstractItemView::viewportEvent :
QCoreApplicationPrivate::sendThroughObjectEventFilters :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QApplicationPrivate::sendMouseEvent :
QSizePolicy::QSizePolicy :
QSizePolicy::QSizePolicy :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QGuiApplicationPrivate::processMouseEvent :
QWindowSystemInterface::sendWindowSystemEvents :
QEventDispatcherWin32::processEvents :
CallWindowProcW :
DispatchMessageW :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QCoreApplication::exec :
main :
BaseThreadInitThunk :
RtlUserThreadStart :
</pre>


*QGIS Info*
QGIS Version: 3.2.0-Bonn
QGIS code revision: commit:bc43194061
Compiled against Qt: 5.9.2
Running against Qt: 5.9.2
Compiled against GDAL: 2.2.4
Running against GDAL: 2.2.4



*System Info*
CPU Type: x86_64
Kernel Type: winnt
Kernel Version: 10.0.17134



_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

--
Matthias Kuhn
[hidden email]
<a href="tel:+41764356763" target="_blank" rel="noreferrer" moz-do-not-send="true">+41 (0)76 435 67 63
_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

--
Matthias Kuhn
[hidden email]
<a href="tel:+41764356763">+41 (0)76 435 67 63

_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: Access to iface in processing alg

Nyall Dawson
In reply to this post by Jean-Baptiste Desbas
On Tue, 10 Jul 2018 at 05:15, Jean-Baptiste Desbas <[hidden email]> wrote:
>
>
> Hi,
>
> I just want to display a messageBar instead of displaying it un the processing output console (feedback.pushInfo) It's ni big deal but i was just confused.

As Matthias has said -- don't do this! Apart from the crashes, it will
also break use of your algorithms from standalone scripts, where iface
is not available. It also means the output is not properly logged, so
users who want to save the log from model execution for later
reference won't have these messages included.

> Do toi have any tips of use case of the differents pushInfo, pushConsoleInfo, etc. ?

Basically you can stick to pushInfo and reportError. Use pushInfo for
informative messages, such as "Building spatial index" or "Found 56
matching features", and reportError for... errors... e.g. "Feature
does not have a point geometry, skipping".

Nyall
_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: Access to iface in processing alg

Jean-Baptiste Desbas
Thanks to you two,

I didn't realize that it can cause other troubles.. So I will continue to use pushInfo/repportError !

Regards,

2018-07-10 2:56 GMT+02:00 Nyall Dawson <[hidden email]>:
On Tue, 10 Jul 2018 at 05:15, Jean-Baptiste Desbas <[hidden email]> wrote:
>
>
> Hi,
>
> I just want to display a messageBar instead of displaying it un the processing output console (feedback.pushInfo) It's ni big deal but i was just confused.

As Matthias has said -- don't do this! Apart from the crashes, it will
also break use of your algorithms from standalone scripts, where iface
is not available. It also means the output is not properly logged, so
users who want to save the log from model execution for later
reference won't have these messages included.

> Do toi have any tips of use case of the differents pushInfo, pushConsoleInfo, etc. ?

Basically you can stick to pushInfo and reportError. Use pushInfo for
informative messages, such as "Building spatial index" or "Found 56
matching features", and reportError for... errors... e.g. "Feature
does not have a point geometry, skipping".

Nyall


_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user