Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to run a Mathematica code repeatedly, even after the kernel shuts down when it is out of memory, because I have designed my program to continue appending the data to a file. Currently, I have to restart the kernel manually every 10 minutes. Does anyone have an idea how one can automate this process? Thanks.

share|improve this question
There's no way to automate this because a fresh kernel won't know what it did in the past. Why do you want to let things get to the point where the kernel crashes? Instead, you can try to use MemoryConstrained to abort the computation when the memory exceeds a certain threshold and then restart it... – R. M. Jul 12 '13 at 18:15
up vote 8 down vote accepted

If you preselect a range of cells before execution you can continue execution past kernel quit using the option below. Selection and evaluation can be automated and done repeatedly.

SetOptions[$FrontEnd, "ClearEvaluationQueueOnKernelQuit" -> False]

Ref :

(MemoryConstrained looks a good solution for your specific problem though.)

share|improve this answer
Thanks! SetOptions works great! – math-student Jul 13 '13 at 1:07

Here is what rm -rf just mentioned, in the form of an example:

  a = Range[10^n], 10000];
 {n, 1, 10}












By using MemoryConstrained, you don't get any changes in the list a after the maximum memory is reached in the above loop, but the loop continues to run.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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