add support to abort evaluation of long running scripts on shutdown

This commit is contained in:
Brad Hefta-Gaub 2016-04-26 16:24:53 -07:00
parent a21bc66fa3
commit 48e63ea828

View file

@ -201,6 +201,8 @@ void ScriptEngine::waitTillDoneRunning() {
// we want the application thread to continue to process events, because the scripts will likely need to // we want the application thread to continue to process events, because the scripts will likely need to
// marshall messages across to the main thread. For example if they access Settings or Menu in any of their // marshall messages across to the main thread. For example if they access Settings or Menu in any of their
// shutdown code. // shutdown code.
QString scriptName = getFilename();
auto startedWaiting = usecTimestampNow(); auto startedWaiting = usecTimestampNow();
while (thread()->isRunning()) { while (thread()->isRunning()) {
// process events for the main application thread, allowing invokeMethod calls to pass between threads // process events for the main application thread, allowing invokeMethod calls to pass between threads
@ -210,14 +212,14 @@ void ScriptEngine::waitTillDoneRunning() {
// if we've been waiting a second or more, then tell the script engine to stop evaluating // if we've been waiting a second or more, then tell the script engine to stop evaluating
if (elapsed > USECS_PER_SECOND) { if (elapsed > USECS_PER_SECOND) {
qDebug() << __FUNCTION__ << "...giving up on evaluation elapsed:" << elapsed << "calling abortEvaluation()"; qDebug() << "giving up on evaluation elapsed:" << elapsed << "calling abortEvaluation() script:" << scriptName;
abortEvaluation(); abortEvaluation();
} }
// if we've been waiting for more than 5 seconds then we should be more aggessive about stopping // if we've been waiting for more than 5 seconds then we should be more aggessive about stopping
static const auto WAITING_TOO_LONG = USECS_PER_SECOND * 5; static const auto WAITING_TOO_LONG = USECS_PER_SECOND * 5;
if (elapsed > WAITING_TOO_LONG) { if (elapsed > WAITING_TOO_LONG) {
qDebug() << __FUNCTION__ << "...giving up on thread elapsed:" << elapsed << "calling thread->quit()"; qDebug() << "giving up on thread elapsed:" << elapsed << "calling thread->quit() script:" << scriptName;
thread()->quit(); thread()->quit();
break; break;
} }