forked from qt-creator/qt-creator
PythonEditor: Fix a leak of console process on shutdown
Give a parent for console process in order to delete it on shutdown. In case the console process was started and the user closed the Creator we were leaking console process instance together with its process. Connect to ConsoleProcess::finished() instead of stubStopped(). There is no point to keep the console open when the process finished (it forces the user to manually close the stub window by pressing enter). Change-Id: I3f14e940f39b32e11bde276e80f3cb630b13d8f7 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -63,9 +63,9 @@ static QAction *createAction(QObject *parent, ReplType type)
|
||||
break;
|
||||
}
|
||||
|
||||
QObject::connect(action, &QAction::triggered, parent, [type] {
|
||||
QObject::connect(action, &QAction::triggered, parent, [type, parent] {
|
||||
Core::IDocument *doc = Core::EditorManager::currentDocument();
|
||||
openPythonRepl(doc ? doc->filePath() : Utils::FilePath(), type);
|
||||
openPythonRepl(parent, doc ? doc->filePath() : Utils::FilePath(), type);
|
||||
});
|
||||
return action;
|
||||
}
|
||||
|
@@ -95,7 +95,7 @@ static QStringList replImportArgs(const FilePath &pythonFile, ReplType type)
|
||||
return {"-c", QString("%1; print('Running \"%1\"')").arg(import)};
|
||||
}
|
||||
|
||||
void openPythonRepl(const FilePath &file, ReplType type)
|
||||
void openPythonRepl(QObject *parent, const FilePath &file, ReplType type)
|
||||
{
|
||||
static const auto workingDir = [](const FilePath &file) {
|
||||
if (file.isEmpty()) {
|
||||
@@ -107,7 +107,7 @@ void openPythonRepl(const FilePath &file, ReplType type)
|
||||
};
|
||||
|
||||
const auto args = QStringList{"-i"} + replImportArgs(file, type);
|
||||
auto process = new ConsoleProcess;
|
||||
auto process = new ConsoleProcess(parent);
|
||||
const FilePath pythonCommand = detectPython(file);
|
||||
process->setCommand({pythonCommand, args});
|
||||
process->setWorkingDirectory(workingDir(file));
|
||||
@@ -122,7 +122,7 @@ void openPythonRepl(const FilePath &file, ReplType type)
|
||||
.arg(commandLine, process->errorString()));
|
||||
process->deleteLater();
|
||||
});
|
||||
QObject::connect(process, &ConsoleProcess::stubStopped, process, &QObject::deleteLater);
|
||||
QObject::connect(process, &ConsoleProcess::finished, process, &QObject::deleteLater);
|
||||
process->start();
|
||||
}
|
||||
|
||||
|
@@ -31,7 +31,7 @@ namespace Python {
|
||||
namespace Internal {
|
||||
|
||||
enum class ReplType { Unmodified, Import, ImportToplevel };
|
||||
void openPythonRepl(const Utils::FilePath &file, ReplType type);
|
||||
void openPythonRepl(QObject *parent, const Utils::FilePath &file, ReplType type);
|
||||
Utils::FilePath detectPython(const Utils::FilePath &documentPath);
|
||||
|
||||
} // namespace Internal
|
||||
|
Reference in New Issue
Block a user