]> git.lyx.org Git - features.git/commitdiff
Fix bug #8032 (timeout when using the Sweave module)
authorEnrico Forestieri <forenr@lyx.org>
Wed, 7 Mar 2012 00:26:17 +0000 (00:26 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Wed, 7 Mar 2012 00:26:17 +0000 (00:26 +0000)
After the timeout elapses, the user is notified that a command is taking
a long time to complete and is given the choice to stop it. If the user
decides to let the command run, the timeout is increased, otherwise the
command is killed. One is prompted a first time after 3 mins, a second
time after 9 mins, a third time after 27 mins, and so on, i.e., the n-th
prompt occurs after 3^n minutes.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@40881 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiProgress.cpp
src/frontends/qt4/GuiProgress.h
src/support/ProgressInterface.h
src/support/Systemcall.cpp
src/support/os.cpp
src/support/os_cygwin.cpp
src/support/os_unix.cpp
src/support/os_win32.cpp
status.20x

index aec058cf8e66110787aa9fe23ce71a0882b90308..ab8c6bd3cfb470284913784acc148ac2ebc765a5 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "qt_helpers.h"
 
+#include "frontends/alert.h"
+
 #include "support/debug.h"
 #include "support/Systemcall.h"
 
@@ -67,6 +69,14 @@ GuiProgress::GuiProgress()
 }
 
 
+int GuiProgress::prompt(docstring const & title, docstring const & question,
+                       int default_button, int cancel_button,
+                       docstring const & b1, docstring const & b2)
+{
+       return Alert::prompt(title, question, default_button, cancel_button, b1, b2);
+}
+
+
 QString GuiProgress::currentTime()
 {
        return QTime::currentTime().toString("hh:mm:ss.zzz");
index 1d80259f71eda3cede75cb4a9ef086827ab61c53..a514733eb7a85bdc03652724171f07e2e29a84ef 100644 (file)
@@ -42,6 +42,10 @@ public:
        void lyxerrDisconnect();
        void lyxerrFlush();
 
+       int prompt(docstring const & title, docstring const & question,
+                  int default_button, int cancel_button,
+                  docstring const & b1, docstring const & b2);
+
        static QString currentTime();
 
 Q_SIGNALS:
index a9b6d2bc432c22351f612f04c96b313264211d48..1efb79a7e3b6296875311eea692fb27b82175218 100644 (file)
@@ -12,6 +12,8 @@
 #ifndef LYX_SUPPORT_PROGRESSINTERFACE_H
 #define LYX_SUPPORT_PROGRESSINTERFACE_H
 
+#include "support/strfwd.h"
+
 class QString;
 
 namespace lyx {
@@ -36,6 +38,9 @@ public:
        virtual void toggleWarning(QString const & title, QString const & msg, QString const & formatted) = 0;
        virtual void error(QString const & title, QString const & message) = 0;
        virtual void information(QString const & title, QString const & message) = 0;
+       virtual int prompt(docstring const & title, docstring const & question,
+                          int default_button, int cancel_button,
+                          docstring const & b1, docstring const & b2) = 0;
 
        virtual void lyxerrConnect() = 0;
        virtual void lyxerrDisconnect() = 0;
index 100023e29d14ee8cdda29cb1564b242344f61692..7d22d592daf9569f0275f6234e1d0da28ecea35b 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "support/debug.h"
 #include "support/filetools.h"
+#include "support/gettext.h"
 #include "support/lstrings.h"
 #include "support/qstring_helpers.h"
 #include "support/Systemcall.h"
@@ -72,6 +73,8 @@ public:
        void toggleWarning(QString const &, QString const &, QString const &) {}
        void error(QString const &, QString const &) {}
        void information(QString const &, QString const &) {}
+       int prompt(docstring const &, docstring const &, int default_but, int,
+                  docstring const &, docstring const &) { return default_but; }
 };
 
 
@@ -363,11 +366,26 @@ void SystemcallPrivate::waitAndProcessEvents()
 }
 
 
+namespace {
+
+bool queryStopCommand(QString const & cmd)
+{
+       docstring text = bformat(_(
+               "The command\n%1$s\nhas not yet completed.\n\n"
+               "Do you want to stop it?"), qstring_to_ucs4(cmd));
+       return ProgressInterface::instance()->prompt(_("Stop command?"), text,
+                       1, 1, _("&Stop it"), _("Let it &run")) == 0;
+}
+
+}
+
+
 bool SystemcallPrivate::waitWhile(State waitwhile, bool process_events, int timeout)
 {
        if (!process_)
                return false;
 
+       bool timedout = false;
        process_events_ = process_events;
 
        // Block GUI while waiting,
@@ -375,8 +393,24 @@ bool SystemcallPrivate::waitWhile(State waitwhile, bool process_events, int time
        if (!process_events_) {
                if (waitwhile == Starting)
                        return process_->waitForStarted(timeout);
-               if (waitwhile == Running)
-                       return process_->waitForFinished(timeout);
+               if (waitwhile == Running) {
+                       int bump = 2;
+                       while (!timedout) {
+                               if (process_->waitForFinished(timeout))
+                                       return true;
+                               bool stop = queryStopCommand(cmd_);
+                               // The command may have finished in the meantime
+                               if (process_->state() == QProcess::NotRunning)
+                                       return true;
+                               if (stop) {
+                                       timedout = true;
+                                       process_->kill();
+                               } else {
+                                       timeout *= bump;
+                                       bump = 3;
+                               }
+                       }
+               }
                return false;
        }
 
@@ -391,10 +425,21 @@ bool SystemcallPrivate::waitWhile(State waitwhile, bool process_events, int time
        // process events while waiting whith timeout
        QTime timer;
        timer.start();
-       while (state == waitwhile && state != Error && timer.elapsed() < timeout) {
+       while (state == waitwhile && state != Error && !timedout) {
                waitAndProcessEvents();
+               if (timer.elapsed() > timeout) {
+                       bool stop = queryStopCommand(cmd_);
+                       // The command may have finished in the meantime
+                       if (process_->state() == QProcess::NotRunning)
+                               break;
+                       if (stop) {
+                               timedout = true;
+                               process_->kill();
+                       } else
+                               timeout *= 3;
+               }
        }
-       return (state != Error) && (timer.elapsed() < timeout);
+       return (state != Error) && !timedout;
 }
 
 
index f36331ccccac11eca163b00e8394b57dd1d0fd50..38c637476822dcd24dc54276ea09af99b84e2eda 100644 (file)
@@ -54,6 +54,12 @@ static string const python2(string const & binary, bool verbose = false)
 }
 
 
+int timeout_min()
+{
+       return 30;
+}
+
+
 string const python()
 {
        // Check whether the first python in PATH is the right one.
index 389b4e2f78d797a281624fbdeca8bed7e762317f..b1c2fefd88de30d68700c028ab232b15e0700708 100644 (file)
@@ -398,12 +398,6 @@ shell_type shell()
 }
 
 
-int timeout_min()
-{
-       return 3;
-}
-
-
 char path_separator(path_type type)
 {
        if (type == TEXENGINE)
index b8a94b2c5680e8a194be628bad162afd56df8d3b..bb6a86b709f299231025dc227e42cd2defa20190 100644 (file)
@@ -222,12 +222,6 @@ shell_type shell()
 }
 
 
-int timeout_min()
-{
-       return 3;
-}
-
-
 char path_separator(path_type)
 {
        return ':';
index 72bf218a04db6e3be44b629d2c8a78c71b91ce43..b58397d202640cc5cac395f913e7c4c8c1b421d1 100644 (file)
@@ -458,12 +458,6 @@ shell_type shell()
 }
 
 
-int timeout_min()
-{
-       return 30;
-}
-
-
 char path_separator(path_type type)
 {
        if (type == TEXENGINE)
index 3372b7c149486fe1e76d92ca5741576f48184859..53629b7635f35da68194f59be5602c3c23f2eb5a 100644 (file)
@@ -43,6 +43,9 @@ What's new
 - New command for forward search with SumatraPDF without the need of an
   external DDE program (requires SumatraPDF version 1.9 or higher).
 
+- When a command takes too long to complete, ask the user for what to do
+  instead of automatically stopping it after a timeout interval (bug 8032).
+
 
 * DOCUMENTATION AND LOCALIZATION