6

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?

saturasl
  • 1,429
  • 7
  • 18
  • 1
    Without a MWE (minimal working example) helping you will be difficult. Please provide code to reproduce the problem. – Yves Klett Oct 03 '13 at 09:23
  • @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... – saturasl Oct 03 '13 at 09:31
  • Can you use Clear or Remove with any success? – Yves Klett Oct 03 '13 at 09:51
  • @ 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. – saturasl Oct 03 '13 at 10:02
  • @Yves Klett I tried to use Clear and Remove instead of Unset, but problem also remains. – saturasl Oct 03 '13 at 10:14

1 Answers1

8

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?

Manipulate[
  Column[{
          Plot[Sin[x - n], {x, 0, 12.4}],
          Button["reset",
                 SelectionMove[EvaluationNotebook[], Previous, Cell];
                 SelectionMove[EvaluationNotebook[], Previous, Cell];
                 NotebookDelete@Cells[GeneratedCell -> True];
                 ClearAll["Global`*"];
                 SelectionEvaluate[EvaluationNotebook[]];
                ]
        }]
 , {n, .3, 11.8}]
Kuba
  • 136,707
  • 13
  • 279
  • 740
  • 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[]. – saturasl Oct 03 '13 at 09:56
  • @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? – Kuba Oct 03 '13 at 10:00
  • 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! – saturasl Oct 03 '13 at 10:08