Hi I am working on an application in Django. I have multiple threads running and I need to check the status of the threads periodically. So I used setInterval() but I want to stop it when I have exception in thread. But it is not stopping and keeps on calling the URL. Here is my code:
function checkThreadsStatus(){
var g_progress_intv = setInterval(function() {
$.post("some_url", function(json_response) {
var jsonObj = eval("(" + (json_response) + ")");
if (jsonObj.exceptionOccur){
clearInterval(g_progress_intv);
g_progress_intv = 0;
}
else{
//do some stuff
}
});
}, 2000);
}
jsonObj.exceptionOccur is a boolean variable. But when it is True setInterval() does not Stop.
Are you calling the
checkThreadsStatus()function multiple times? The intervals might possibly be stopping, but you are declaring them on top of each other. Use some alerts orconsole.login there to determine the actual state of the variables.