Skip to content
Permalink
Browse files

[WFS provider] Fix deadlock when adding WFS layer to project from Pyt…

…hon console (fixes #17087)
  • Loading branch information
rouault committed Nov 9, 2017
1 parent 032ca68 commit 75c41f5e18f32dcf3ce7fd7c13b3838e8e7912db
@@ -755,11 +755,25 @@ void QgsWFSThreadedFeatureDownloader::stop()
}
}

void QgsWFSThreadedFeatureDownloader::startAndWait()
{
start();

QMutexLocker locker( &mWaitMutex );
while ( !mDownloader )
{
mWaitCond.wait( &mWaitMutex );
}
}

void QgsWFSThreadedFeatureDownloader::run()
{
// We need to construct it in the run() method (i.e. in the new thread)
mDownloader = new QgsWFSFeatureDownloader( mShared );
emit ready();
{
QMutexLocker locker( &mWaitMutex );
mWaitCond.wakeOne();
}
mDownloader->run( true, /* serialize features */
0 /* user max features */ );
}
@@ -25,6 +25,8 @@
#include <memory>
#include <QProgressDialog>
#include <QPushButton>
#include <QMutex>
#include <QWaitCondition>

class QgsWFSProvider;
class QgsWFSSharedData;
@@ -168,20 +170,21 @@ class QgsWFSThreadedFeatureDownloader: public QThread
//! Return downloader object
QgsWFSFeatureDownloader *downloader() { return mDownloader; }

//! Starts thread and wait for it to be started
void startAndWait();

//! Stops (synchronously) the download
void stop();

signals:
//! Emitted when the thread is ready
void ready();

protected:
//! Inherited from QThread. Starts the download
void run() override;

private:
QgsWFSSharedData *mShared; //!< Mutable data shared between provider and feature sources
QgsWFSFeatureDownloader *mDownloader = nullptr;
QWaitCondition mWaitCond;
QMutex mWaitMutex;
};

class QgsWFSFeatureSource;
@@ -540,10 +540,7 @@ int QgsWFSSharedData::registerToCache( QgsWFSFeatureIterator *iterator, const Qg
mDownloadFinished = false;
mComputedExtent = QgsRectangle();
mDownloader = new QgsWFSThreadedFeatureDownloader( this );
QEventLoop loop;
connect( mDownloader, &QgsWFSThreadedFeatureDownloader::ready, &loop, &QEventLoop::quit );
mDownloader->start();
loop.exec( QEventLoop::ExcludeUserInputEvents );
mDownloader->startAndWait();
}
if ( mDownloadFinished )
return -1;

0 comments on commit 75c41f5

Please sign in to comment.
You can’t perform that action at this time.