Forcing MATLAB script timeout without modification

5 views (last 30 days)
I am running many scripts to analyze time, memory, etc., the problem is some hang for a long time (2-3 minutes) and in that case, I just want to "skip" them and not let them finish. The problem is I can not figure out how to force a timeout on the scripts. I thought by adding in a timer in a try/catch block that throws an error after 30 seconds, it could be a workaround, but it turns out the timer will display an error on the console, but does nothing at all to signal to the try catch block that an error occured.
I had two other ideas, but I am not sure exactly how they would work. 1) Calling a batch file that ran the script, but could also kill it after 30 seconds, my one big concern would be getting all the test results back into the over-arching program running the tests, but I think that can still be done relatively easily. 2) This one is a little more crazy and almost positive it would not work the way I am thinking about it, but somehow modifying or deleting the script it was running after 30 seconds and then replacing it with a copy if it did delete or modify it to stop.
Any ideas or suggestions?
Thanks!

Accepted Answer

Walter Roberson
Walter Roberson on 22 Jan 2013
Deleting the script as it is running will probably not work, at least not in later MATLAB. MATLAB reads and parses the entire script and keeps it in memory until it is told to "clear" the script.
There is no documented way to force a timeout. The only publically known mechanism is to kill the process.

More Answers (0)

Categories

Find more on Testing Frameworks in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!