Skip to content

Commit

Permalink
Fix the deadlock in trikPythonRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
MinyazevR committed Dec 23, 2024
1 parent 14a119d commit 4757798
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions trikScriptRunner/src/trikPythonRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdexcept>
#include <PythonQt.h>
#include <QCoreApplication>
#include <QAbstractEventDispatcher>

#include "trikPythonRunner.h"
#include "src/pythonEngineWorker.h"
Expand Down Expand Up @@ -51,6 +52,16 @@ TrikPythonRunner::~TrikPythonRunner()
connect(mWorkerThread, &QThread::finished, &wait, &QEventLoop::quit);
mScriptEngineWorker->stopScript();
mWorkerThread->quit();

auto *dispatcher = QAbstractEventDispatcher::instance(mWorkerThread);
if (dispatcher) {
connect(dispatcher, &QAbstractEventDispatcher::aboutToBlock, [dispatcher]() {
if (dispatcher) {
dispatcher->interrupt();
}
});
}

// We need an event loop to process pending calls from dying thread to the current
// mWorkerThread.wait(); // <-- !!! blocks pending calls
wait.exec();
Expand Down

0 comments on commit 4757798

Please sign in to comment.