Skip to content

Commit

Permalink
fix: [codegeex] thread issue of generate file index
Browse files Browse the repository at this point in the history
Log: as title
  • Loading branch information
LiHua000 authored and deepin-mozart committed Oct 31, 2024
1 parent 76ab3f2 commit 009647d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/plugins/codegeex/codegeexmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,17 @@ void CodeGeeXManager::installConda()

void CodeGeeXManager::generateRag(const QString &projectPath)
{
if (indexingProject.contains(projectPath))
mutex.lock();
if (indexingProject.contains(projectPath)) {
mutex.unlock();
return;
}
indexingProject.append(projectPath);
mutex.unlock();
QProcess *process = new QProcess;
QObject::connect(QApplication::instance(), &QApplication::aboutToQuit, process, [process]() {
process->kill();
});
}, Qt::DirectConnection);

QObject::connect(process, &QProcess::readyReadStandardError, process, [process]() {
qInfo() << "Error:" << process->readAllStandardError() << "\n";
Expand All @@ -541,7 +545,9 @@ void CodeGeeXManager::generateRag(const QString &projectPath)
QObject::connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
process, [=](int exitCode, QProcess::ExitStatus exitStatus) {
qInfo() << "Python script finished with exit code" << exitCode << "Exit!!!";
mutex.lock();
indexingProject.removeOne(projectPath);
mutex.unlock();
auto success = process->readAllStandardError().isEmpty();
emit generateDone(projectPath, !success);
if (!success)
Expand All @@ -559,6 +565,8 @@ void CodeGeeXManager::generateRag(const QString &projectPath)
if (!QFileInfo(pythonPath).exists())
return;
process->start(pythonPath, QStringList() << generatePyPath << modelPath << projectPath);
if (QThread::currentThread() != qApp->thread()) // incase thread exit before process done. cause slot function can`t work
process->waitForFinished();
}

/*
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/codegeex/codegeexmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QObject>
#include <QMap>
#include <QTimer>
#include <QMutex>

struct RecordData
{
Expand Down Expand Up @@ -153,6 +154,7 @@ public Q_SLOTS:
bool isRunning { false };
bool condaInstalled { false };
QTimer installCondaTimer;
QMutex mutex;
QStringList indexingProject {};
};

Expand Down
10 changes: 6 additions & 4 deletions src/plugins/codegeex/eventreceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ void CodeGeeXReceiver::processActionInvokedEvent(const dpf::Event &event)

void CodeGeeXReceiver::processOpenProjectEvent(const dpf::Event &event)
{
auto projectPath = event.property("workspace").toString();
QJsonObject results = CodeGeeXManager::instance()->query(projectPath, "", 1);
if (results["Chunks"].toArray().size() != 0) // project has generated, update it
CodeGeeXManager::instance()->generateRag(projectPath);
QtConcurrent::run([=](){
auto projectPath = event.property("workspace").toString();
QJsonObject results = CodeGeeXManager::instance()->query(projectPath, "", 1);
if (results["Chunks"].toArray().size() != 0) // project has generated, update it
CodeGeeXManager::instance()->generateRag(projectPath);
});
}

void CodeGeeXReceiver::processSwitchToWidget(const dpf::Event &event)
Expand Down

0 comments on commit 009647d

Please sign in to comment.