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 309b1c8 commit 505e36599296ee0b7c75761e9fb4d267a43b84be
@@ -759,11 +759,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 */ );
}
@@ -24,6 +24,8 @@

#include <QProgressDialog>
#include <QPushButton>
#include <QMutex>
#include <QWaitCondition>

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

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

signals:
/** Emitted when the thread is ready */
void ready();
//! Starts thread and wait for it to be started
void startAndWait();

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

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

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

0 comments on commit 505e365

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