I have written a Manipulate code carrying out some very complicated tasks. There is no problem for the first run, but if I click the reset button to reset all variables to their initial states (which is also ok) and click the run button a second time, then it is very likely that the Mathematica kernel will crash during the re-run progress, the frequency for such crash happening is about 9 out of 10 times.

I have spent almost a month trying to track down the source of this problem, but failed. I also asked the Wolfram support team, they suggested to implement the Quit function in the reset button as a workaround, such that the reset button will make the kernel quit, since the first run is always ok.

Now the problem is, I cannot directly put Quit[] inside the button, for by doing this the kernel loses all definiton about the enclosing Manipulate. So I need the reset button doing two tasks:

  1. Quit the kernel.
  2. Make Mathematica automatically re-run the enclosing Manipulate code.

I wonder if this is possible?

  • 1
    $\begingroup$ Without a MWE (minimal working example) helping you will be difficult. Please provide code to reproduce the problem. $\endgroup$
    – Yves Klett
    Oct 3 '13 at 9:23
  • $\begingroup$ @Yves Klett The problem is I cannot come up with a minimal working example, because I have not tracked down the source of the crash. My code is about 900 lines, I fear it is too long to post here... $\endgroup$
    – saturasl
    Oct 3 '13 at 9:31
  • $\begingroup$ Can you use Clear or Remove with any success? $\endgroup$
    – Yves Klett
    Oct 3 '13 at 9:51
  • $\begingroup$ @ Yves klett I tried to use Unset, ClearSystemCache,$HistoryLength, SaveDefinitions -> True, SynchronousInitialization -> True, SynchronousUpdating -> True, and DynamicEvaluationTimeout -> Infinity. But the problem remains. There must be no problem for any function since the first run is always ok. I suppose something unusual happened in the kernel during the re-run process. $\endgroup$
    – saturasl
    Oct 3 '13 at 10:02
  • $\begingroup$ @Yves Klett I tried to use Clear and Remove instead of Unset, but problem also remains. $\endgroup$
    – saturasl
    Oct 3 '13 at 10:14

I suppose that your problem is rather in not efficient/proper Manipulate structure but since it is 900 lines long I think we can't help to fix it.

Here's the solution you've asked, I think so, isn't it?

          Plot[Sin[x - n], {x, 0, 12.4}],
                 SelectionMove[EvaluationNotebook[], Previous, Cell];
                 SelectionMove[EvaluationNotebook[], Previous, Cell];
                 NotebookDelete@Cells[GeneratedCell -> True];
 , {n, .3, 11.8}]
  • $\begingroup$ Yes, in my code,the main operation is executed from inside the run button, not in the Manipulate body. About your code, I run it, the cell is deleted, but not generated again, even after I remove the ; after SelectionEvaluate[]. $\endgroup$
    – saturasl
    Oct 3 '13 at 9:56
  • $\begingroup$ @saturasl I've made one edit couple minutes ago, try if you have the exactly same version as it is now. What is Run button? $\endgroup$
    – Kuba
    Oct 3 '13 at 10:00
  • $\begingroup$ Ah, the run button, I was talknig about the button in my own code, not yours. Now your code works, exactly what I expect, Thanks! $\endgroup$
    – saturasl
    Oct 3 '13 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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