Fix bug #8032 (timeout when using the Sweave module)

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
This commit is contained in:
Enrico Forestieri 2012-03-07 00:26:17 +00:00
parent 8bdd1082fa
commit b067c04309
9 changed files with 77 additions and 22 deletions

View 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");

View 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:

View 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;

View 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;
}

View 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.

View File

@ -398,12 +398,6 @@ shell_type shell()
}
int timeout_min()
{
return 3;
}
char path_separator(path_type type)
{
if (type == TEXENGINE)

View File

@ -222,12 +222,6 @@ shell_type shell()
}
int timeout_min()
{
return 3;
}
char path_separator(path_type)
{
return ':';

View File

@ -458,12 +458,6 @@ shell_type shell()
}
int timeout_min()
{
return 30;
}
char path_separator(path_type type)
{
if (type == TEXENGINE)

View 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