cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
mann
Level III

Timeout of the try function

I have a single script that calls many other scripts for reporting processes on equipment and building reports. Sometimes the data coming off the process tools includes errors that JMP cannot handle.  So I have wrapped the calls in a Try() function like this:

For(ii=1, ii < nitems(BulkScriptsToRun),  ii++, 
	try(	
		Include( BulkScriptsToRun[ii] );
	);	
);

Sometimes the included script does not crash, but neither does it finish.

While this could probably be fixed by editing the script and how it processes the data - they are not my scripts to edit.

Is there a way to have the try function consider the try a failure if it takes more than 1 hour, for example?

Is there another way to achieve this? Is there a way to tell the Try() that is should give up?

 

Thanks

 

 

4 REPLIES 4
Craige_Hales
Super User

Re: Timeout of the try function

No, try() does not have a timeout mechanism; it is very similar to the C++ try-throw-catch mechanism. As you are guessing, you'd need to put the logic in each of the included scripts, which could do something like

startSeconds = tickSeconds();
...
while(...
   if( tickseconds() - startSeconds > 100, throw("Used more than 100 seconds") );
...)

I know you said you can't open up those scripts for editing, but if you did, you might want to have them make a callback to your code to indicate progress. Then you could do the throw from the callback if needed. Either way you'd need to find a point in each of the scripts where a loop is repeating something, and the timeout depends on the script being reasonably well behaved (to keep checking the time).

 

The windows task scheduler might also be part of the solution; I've not used it but there have been a number of threads asking questions about it. Can I close the jmp program from a script?  might suggest something.

 

Craige
jthi
Super User

Re: Timeout of the try function

This does sound like something that could be done with Windows Task Scheduler if you cannot modify the scripts. Create script which includes the other scripts, manage all errors which you can in your "inclusion" script and add timeout to schedulers task. After it runs out of time it will terminate the execution wherever it got.

 

In general running batch of scripts which you don't have control over can quickly get messy because you might have to be handle quite a lot of different things (I have had to do something like this). Below are some problems (or opportunities of improvement)  I faced:

  • Manage namespace collision
  • Delete/Clear unnecessary symbols
  • Survive from situation where the scripts do not use Names Default To Here(1)
  • Survive from usage of Clear Symbols / Delete Globals in the included script
  • Close unnecessary data tables and reports to save memory
  • Catching errors which would stop JMP
  • Usage of Exit/Quit in the included scripts
  • Log script execution to know what got executed properly

Most of these are way easier to handle by training / modifying the scripts which are included.

-Jarmo
mann
Level III

Re: Timeout of the try function

I am running the master script from Task Scheduler.  And I can timeout there. But if one of the script has the same error hour after hour, day after day, all the scripts below that one on the list will never be run.  

They way the master script is organized, the scripts later on the list are run less frequently, so it might takes weeks to notice that they are being skipped entirely.  I could just reverse the order of the list - but then the scripts that need to be run every 10 minutes get skipped every time until I fix the problem in the problematic script (this is worse).

Also, the master script reports its own progress after all the scripts are run.  This would never happen if the task is killed.

 

My current solution is: comment out the problematic script and wait for the responsible party to care enough to fix it.

It works. 

vince_faller
Super User (Alumni)

Re: Timeout of the try function

Does one require the other to work?  If you master script is really just including a bunch of separate scripts, Why not just Run each one as a different task?  Then it doesn't matter.  Each one would open  its own instance of JMP and run and then close JMP.  You could control the timeout of each one individually as well.  

Vince Faller - Predictum