Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash when using QThreadPool + QRunnable #27457

Closed
qgib opened this issue Aug 15, 2018 · 3 comments
Closed

crash when using QThreadPool + QRunnable #27457

qgib opened this issue Aug 15, 2018 · 3 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption Plugins

Comments

@qgib
Copy link
Contributor

qgib commented Aug 15, 2018

Author Name: Min Min (Min Min)
Original Redmine Issue: 19630
Affected QGIS version: 3.0.3
Redmine category:python_plugins


User Feedback

crash when using QThreadPool + QRunnable in plugin

no GUI updating function is executed in QRunnable. QRunnable writes data to local file, create a QgsVectorLayer, getFeatures, fields, addFeatures, addAttributes (fields) to QgsVectorLayer/QgsDataProvider. When editing, QMutex and QMutexLocker is used.

tasks assigned to QThreadPool has finished sucessfully, QThreadPool.activeThreadCount() returns 0

After tasks finished around 30-60 sec, QGIS crash

Report Details

Crash ID: a279b085a2ce54c5ff69e8b1e03c403266d4bf00

Stack Trace

QCoreApplication::notifyInternal2 :
QEventDispatcherWin32Private::sendTimerEvent :
QEventDispatcherWin32::processEvents :
CallWindowProcW :
DispatchMessageW :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QCoreApplication::exec :
main :
BaseThreadInitThunk :
RtlUserThreadStart :

QGIS Info
QGIS Version: 3.0.3-Girona
QGIS code revision: 8a899c8
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.15063

@qgib
Copy link
Contributor Author

qgib commented Aug 22, 2018

Author Name: Min Min (Min Min)


Error caused by reading feature from a QgsVectorLayer in a QThread. As QgsVectorLayer use QgsConnectionPool for fetching feature, and QgsConnectionPool is singleton and always run in main thread (not thread-safe)

timerEvent in Stack Trace is caused by this connection pool. Whether this is a bug, or by design is unclear.

@qgib
Copy link
Contributor Author

qgib commented Aug 22, 2018

Author Name: Nyall Dawson (@nyalldawson)


It's not safe to fetch features directly from a thread - you need to first obtain the feature iterator in the main thread, and then interested over the features in the spawned thread.

@qgib
Copy link
Contributor Author

qgib commented Sep 3, 2018

Author Name: Min Min (Min Min)


getting feature iterator in main thread and getFeatures in spawned thread works without crash.
problem resolved !


  • status_id was changed from Open to Closed

@qgib qgib closed this as completed Sep 3, 2018
@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Plugins Crash/Data Corruption labels May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption Plugins
Projects
None yet
Development

No branches or pull requests

1 participant