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

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

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!


1 Answer 1


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


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.

  • $\begingroup$ Thanks, but when I write TimeConstrained[SelectionEvaluate[nb1], 5], it does not abort the evaluation. $\endgroup$
    – Alex
    Oct 9, 2015 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, 2015 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.