History

add support to abort evaluation of long running scripts on shutdown

Brad Hefta-Gaub committed 10 years ago

Commit 48e63ea1 parent a21bc661 file · +4 −2Browse 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+4−2
@@ -201,6 +201,8 @@ void ScriptEngine::waitTillDoneRunning() { · 200 unmodified lines
201 // we want the application thread to continue to process events, because the scripts will likely need to201 // we want the application thread to continue to process events, because the scripts will likely need to
202 // marshall messages across to the main thread. For example if they access Settings or Menu in any of their202 // marshall messages across to the main thread. For example if they access Settings or Menu in any of their
203 // shutdown code.203 // shutdown code.
204 QString scriptName = getFilename();
205
204 auto startedWaiting = usecTimestampNow();206 auto startedWaiting = usecTimestampNow();
205 while (thread()->isRunning()) {207 while (thread()->isRunning()) {
206 // process events for the main application thread, allowing invokeMethod calls to pass between threads208 // process events for the main application thread, allowing invokeMethod calls to pass between threads
@@ -210,14 +212,14 @@ void ScriptEngine::waitTillDoneRunning() { · 3 unmodified lines
210 212
211 // if we've been waiting a second or more, then tell the script engine to stop evaluating213 // if we've been waiting a second or more, then tell the script engine to stop evaluating
212 if (elapsed > USECS_PER_SECOND) {214 if (elapsed > USECS_PER_SECOND) {
213 qDebug() << __FUNCTION__ << "...giving up on evaluation elapsed:" << elapsed << "calling abortEvaluation()";215 qDebug() << "giving up on evaluation elapsed:" << elapsed << "calling abortEvaluation() script:" << scriptName;
214 abortEvaluation();216 abortEvaluation();
215 }217 }
216 218
217 // if we've been waiting for more than 5 seconds then we should be more aggessive about stopping219 // if we've been waiting for more than 5 seconds then we should be more aggessive about stopping
218 static const auto WAITING_TOO_LONG = USECS_PER_SECOND * 5;220 static const auto WAITING_TOO_LONG = USECS_PER_SECOND * 5;
219 if (elapsed > WAITING_TOO_LONG) {221 if (elapsed > WAITING_TOO_LONG) {
220 qDebug() << __FUNCTION__ << "...giving up on thread elapsed:" << elapsed << "calling thread->quit()";222 qDebug() << "giving up on thread elapsed:" << elapsed << "calling thread->quit() script:" << scriptName;
221 thread()->quit();223 thread()->quit();
222 break;224 break;
223 }225 }