mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 02:03:11 +02:00
Throw to stop non-evaluating scripts
This commit is contained in:
parent
7e82494a66
commit
1107882be2
1 changed files with 16 additions and 8 deletions
|
@ -304,17 +304,25 @@ void ScriptEngine::wait() {
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
// If the final evaluation takes too long, then tell the script engine to stop evaluating
|
// If the final evaluation takes too long, then tell the script engine to stop evaluating
|
||||||
static const auto MAX_SCRIPT_QUITTING_TIME = 0.5 * MAX_SCRIPT_EVALUATION_TIME;
|
|
||||||
auto elapsedUsecs = usecTimestampNow() - startedWaiting;
|
auto elapsedUsecs = usecTimestampNow() - startedWaiting;
|
||||||
if (elapsedUsecs > MAX_SCRIPT_EVALUATION_TIME) {
|
if (elapsedUsecs > MAX_SCRIPT_EVALUATION_TIME) {
|
||||||
qCDebug(scriptengine).nospace() <<
|
workerThread->quit();
|
||||||
"Script Engine has been running too long, aborting:" << getFilename();
|
|
||||||
abortEvaluation(); // break out of current evaluation
|
|
||||||
|
|
||||||
// Wait for the scripting thread to stop running
|
if (isEvaluating()) {
|
||||||
if (!workerThread->wait(MAX_SCRIPT_QUITTING_TIME)) {
|
qCWarning(scriptengine) << "Script Engine has been running too long, aborting:" << getFilename();
|
||||||
qCWarning(scriptengine).nospace() <<
|
abortEvaluation();
|
||||||
"Script Engine has been aborting too long, terminating:" << getFilename();
|
} else {
|
||||||
|
qCWarning(scriptengine) << "Script Engine has been running too long, throwing:" << getFilename();
|
||||||
|
auto context = currentContext();
|
||||||
|
if (context) {
|
||||||
|
context->throwError("Timed out during shutdown");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the scripting thread to stop running, as
|
||||||
|
// flooding it with aborts/exceptions will persist it longer
|
||||||
|
static const auto MAX_SCRIPT_QUITTING_TIME = 0.5 * MSECS_PER_SECOND;
|
||||||
|
if (workerThread->wait(MAX_SCRIPT_QUITTING_TIME)) {
|
||||||
workerThread->terminate();
|
workerThread->terminate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue