1
$\begingroup$

I use the following code to evaluate a series of notebooks:

nb1 = NotebookOpen["C:\\Users\\....nb"];
SelectionMove[nb1, All, Notebook]
SelectionEvaluate[nb1]

where "..." refers to the exact address in my computer. The above code is repeated 24 times to evaluate 24 different notebooks. These 24 notebooks are equally distributed among 4 kernels so as to reduce the computational time. I aim to do all my computations in 12 hours, which means that I need to run every single notebook in 2 hours (i.e., either it gives me the result within 2 hours, or it'll be aborted at the end of two hours). So, the question is how can an evaluation be automatically terminated (i.e., aborted) after an elapsed time of two hours?

Any idea/help will be appreciated!

$\endgroup$
2
$\begingroup$

What you're looking for is TimeConstrained, see the doc.

TimeConstrained[Table[i,{i,1,1000000,1}],.5]

will evaluate only for 0.5s. Depending on what you want to achieve, you can also use Reap/Sow to keep track of your evaluations so that they are not lost completely when evaluation aborts.

$\endgroup$
2
  • $\begingroup$ Thanks, but when I write TimeConstrained[SelectionEvaluate[nb1], 5], it does not abort the evaluation. $\endgroup$
    – Alex
    Oct 9 '15 at 0:57
  • $\begingroup$ @Alex you could probably wrap the TimeConstrained around the cells inside your notebooks you want to run. That's definitely not a neat way but should at least work - assuming the cell structure allows that simple approach. $\endgroup$
    – Lukas
    Oct 9 '15 at 8:57

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .