Bug report #19630

crash when using QThreadPool + QRunnable

Added by Min Min over 2 years ago. Updated about 2 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Python plugins
Affected QGIS version:3.0.3 Regression?:No
Operating System:Windows 10 x64 Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:Yes Copied to github as #:27457

Description

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: 8a899c8758
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

History

#1 Updated by Min Min over 2 years ago

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.

#2 Updated by Nyall Dawson over 2 years ago

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.

#3 Updated by Min Min about 2 years ago

  • Status changed from Open to Closed

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

Also available in: Atom PDF