Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all
Unified · Split
| @@ -304,17 +304,25 @@ void ScriptEngine::wait() { · 303 unmodified lines | ||
| 304 | 304 | QCoreApplication::processEvents(); |
| 305 | 305 | |
| 306 | 306 | // 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 | 307 | auto elapsedUsecs = usecTimestampNow() - startedWaiting; |
| 309 | 308 | if (elapsedUsecs > MAX_SCRIPT_EVALUATION_TIME) { |
| 310 | − qCDebug(scriptengine).nospace() << | |
| 311 | − "Script Engine has been running too long, aborting:" << getFilename(); | |
| 312 | − abortEvaluation(); // break out of current evaluation | |
| 313 | − | |
| 314 | − // Wait for the scripting thread to stop running | |
| 315 | − if (!workerThread->wait(MAX_SCRIPT_QUITTING_TIME)) { | |
| 316 | − qCWarning(scriptengine).nospace() << | |
| 317 | − "Script Engine has been aborting too long, terminating:" << getFilename(); | |
| 309 | + workerThread->quit(); | |
| 310 | + | |
| 311 | + if (isEvaluating()) { | |
| 312 | + qCWarning(scriptengine) << "Script Engine has been running too long, aborting:" << getFilename(); | |
| 313 | + abortEvaluation(); | |
| 314 | + } else { | |
| 315 | + qCWarning(scriptengine) << "Script Engine has been running too long, throwing:" << 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 | 326 | workerThread->terminate(); |
| 319 | 327 | } |
| 320 | 328 | } |