History

Throw to stop non-evaluating scripts

Zach Pomerantz committed 10 years ago

Commit 11078821 parent 7e824941 file · +17 −9Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+17−9
@@ -304,17 +304,25 @@ void ScriptEngine::wait() { · 303 unmodified lines
304 QCoreApplication::processEvents();304 QCoreApplication::processEvents();
305 305
306 // If the final evaluation takes too long, then tell the script engine to stop evaluating306 // If the final evaluation takes too long, then tell the script engine to stop evaluating
307 static const auto MAX_SCRIPT_QUITTING_TIME = 0.5 * MAX_SCRIPT_EVALUATION_TIME;
308 auto elapsedUsecs = usecTimestampNow() - startedWaiting;307 auto elapsedUsecs = usecTimestampNow() - startedWaiting;
309 if (elapsedUsecs > MAX_SCRIPT_EVALUATION_TIME) {308 if (elapsedUsecs > MAX_SCRIPT_EVALUATION_TIME) {
310 qCDebug(scriptengine).nospace() <<309 workerThread->quit();
311 "Script Engine has been running too long, aborting:" << getFilename();310
312 abortEvaluation(); // break out of current evaluation311 if (isEvaluating()) {
313 312 qCWarning(scriptengine) << "Script Engine has been running too long, aborting:" << getFilename();
314 // Wait for the scripting thread to stop running313 abortEvaluation();
315 if (!workerThread->wait(MAX_SCRIPT_QUITTING_TIME)) {314 } else {
316 qCWarning(scriptengine).nospace() <<315 qCWarning(scriptengine) << "Script Engine has been running too long, throwing:" << getFilename();
317 "Script Engine has been aborting too long, terminating:" << getFilename();316 auto context = currentContext();
317 if (context) {
318 context->throwError("Timed out during shutdown");
319 }
320 }
321
322 // Wait for the scripting thread to stop running, as
323 // flooding it with aborts/exceptions will persist it longer
324 static const auto MAX_SCRIPT_QUITTING_TIME = 0.5 * MSECS_PER_SECOND;
325 if (workerThread->wait(MAX_SCRIPT_QUITTING_TIME)) {
318 workerThread->terminate();326 workerThread->terminate();
319 }327 }
320 }328 }