[education/rkward] /: Allow to restart R backend.

Thomas Friedrichsmeier null at kde.org
Sat Jun 4 20:55:53 BST 2022


Git commit b76839e467d0a57aa2807075e8ddabe5c0eb243e by Thomas Friedrichsmeier.
Committed on 03/06/2022 at 21:46.
Pushed by tfry into branch 'master'.

Allow to restart R backend.

This works suprisingly well, already, but needs quite a bit more work UI-wise.

CCMAIL: meik.michalke at uni-duesseldorf.de

M  +6    -0    ChangeLog
M  +4    -2    rkward/agents/rkdebughandler.cpp
M  +5    -0    rkward/rbackend/rkrinterface.cpp
M  +2    -0    rkward/rbackend/rksessionvars.cpp
M  +6    -0    rkward/rkward.cpp
M  +3    -1    rkward/rkwardui.rc

https://invent.kde.org/education/rkward/commit/b76839e467d0a57aa2807075e8ddabe5c0eb243e

diff --git a/ChangeLog b/ChangeLog
index 38590c32..1fe4d5d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 - Fix problem handling rkward:// links from dialogs on some sytems
 - Allow to select search provider, when searching for a term online
+- Experimental: Add option to restart R backend
+  - TODO: fix mem-leaks
+  - TODO: fix action label / placemnt / add confirmation dialog, etc.
+  - TODO: make sure to close all data editors, object viewers, and plots
+  - TODO: offer in backend crash message?
+  - TODO: In case R version has changed, check setup?
 - Fix object name completion for (irregular) names starting with numbers or underscores
 - Crosstabs N to N: Simplify labels, add option to control table layout
 - Change mechanism for detection of object changes
diff --git a/rkward/agents/rkdebughandler.cpp b/rkward/agents/rkdebughandler.cpp
index d7266d45..3596e414 100644
--- a/rkward/agents/rkdebughandler.cpp
+++ b/rkward/agents/rkdebughandler.cpp
@@ -1,6 +1,6 @@
 /*
 rkdebughandler - This file is part of RKWard (https://rkward.kde.org). Created: Wed Oct 19 2011
-SPDX-FileCopyrightText: 2011 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2011-2022 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -11,7 +11,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 
 #include "../debug.h"
 
-RKDebugHandler* RKDebugHandler::_instance = 0;
+RKDebugHandler* RKDebugHandler::_instance = nullptr;
 
 RKDebugHandler::RKDebugHandler (QObject *parent) : QObject (parent) {
 	RK_TRACE (APP);
@@ -24,6 +24,8 @@ RKDebugHandler::RKDebugHandler (QObject *parent) : QObject (parent) {
 
 RKDebugHandler::~RKDebugHandler () {
 	RK_TRACE (APP);
+	RK_ASSERT(_instance == this);
+	_instance = nullptr;
 }
 
 void RKDebugHandler::debugCall (RBackendRequest *request, RCommand *command) {
diff --git a/rkward/rbackend/rkrinterface.cpp b/rkward/rbackend/rkrinterface.cpp
index 4dea3b49..9d53fc89 100644
--- a/rkward/rbackend/rkrinterface.cpp
+++ b/rkward/rbackend/rkrinterface.cpp
@@ -868,6 +868,11 @@ void RInterface::processRBackendRequest (RBackendRequest *request) {
 			message += i18n ("\nThe R backend will be shut down immediately. This means, you can not use any more functions that rely on it. I.e. you can do hardly anything at all, not even save the workspace (but if you're lucky, R already did that). What you can do, however, is save any open command-files, the output, or copy data out of open data editors. Quit RKWard after that. Sorry!");
 			RKErrorDialog::reportableErrorMessage (0, message, QString (), i18n ("R engine has died"), "r_engine_has_died");
 			emit backendStatusChanged(Dead);
+			while (!all_current_commands.isEmpty()) {
+				auto c = all_current_commands.takeLast();
+				c->status |= RCommand::Failed;
+				handleCommandOut(c);
+			}
 		}
 	} else {
 		RK_ASSERT (false);
diff --git a/rkward/rbackend/rksessionvars.cpp b/rkward/rbackend/rksessionvars.cpp
index da6b495c..60b846dc 100644
--- a/rkward/rbackend/rksessionvars.cpp
+++ b/rkward/rbackend/rksessionvars.cpp
@@ -38,6 +38,8 @@ RKSessionVars::RKSessionVars (RInterface *parent) : QObject (parent) {
 
 RKSessionVars::~RKSessionVars () {
 	RK_TRACE (RBACKEND);
+	RK_ASSERT(_instance == this);
+	_instance = nullptr;
 }
 
 void RKSessionVars::setInstalledPackages (const QStringList &new_list) {
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 050d75f4..4d6ef19d 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -611,6 +611,12 @@ void RKWardMainWindow::initActions() {
 // TODO: A way to add R-script-save actions, dynamically, would be nice
 	save_actions_plug_point = save_any_action->addSeparator ();
 	//save_any_action->addAction (proxy_export); -> later
+
+	auto restart_r = actionCollection()->addAction("restart_r");
+	restart_r->setText(i18n("Restart R Backend"));
+	connect(restart_r, &QAction::triggered, this, [this]() {
+		if (RInterface::instance()->backendIsDead()) startR();
+	});
 }
 
 /*
diff --git a/rkward/rkwardui.rc b/rkward/rkwardui.rc
index 039899a3..c5135896 100644
--- a/rkward/rkwardui.rc
+++ b/rkward/rkwardui.rc
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui>
-<kpartgui name="rkward_main" version="722">
+<kpartgui name="rkward_main" version="741">
 <MenuBar>
 	<!-- The Main Window ui.rc is the only one, where merging happens, reliably. That is, why we need to define
 	     a lot of merge points, here, which can then be used be mdi windows and their children.
@@ -90,6 +90,8 @@
 		<Separator append="configure_merge"/>
 		<Action name="setup_wizard" append="configure_merge"/>
 		<Action name="configure_packages" append="configure_merge"/>
+		<Separator append="configure_merge"/>
+		<Action name="restart_r" append="configure_merge"/>
 	</Menu>
 
 	<Menu name="help"><text>&Help</text>



More information about the rkward-tracker mailing list