10
$\begingroup$

The following procedure can be easily aborted using Evaluation > Abort Evaluation menu item:

Do[j + k, {j, 1, 10000}, {k, 1, 10000}]

But it is not possible if NotebookEvaluate was used:

nb = CreateDocument[ ExpressionCell[Defer[Plot[Sin[x], {x, 0, 2 Pi}]], "Input"]]
NotebookEvaluate[nb, InsertResults -> True];

Now run this again:

Do[j+k,{j,1,10000},{k,1,10000}]

and try to abort. It does not work and the loop is on.

Anyone knows why? Is there any alternative to NotebookEvaluate?

$\endgroup$
  • 1
    $\begingroup$ I rephrased the question and made the example self contained. Feel free to revert my changes. p.s. +1, interesting. $\endgroup$ – Kuba Jan 18 at 10:22
  • $\begingroup$ @Kuba Thanks! Your rephrase seems great! $\endgroup$ – Veteran Jan 18 at 10:25
  • 2
    $\begingroup$ WRI says it is a 'known issue' so I guess bugs applies. $\endgroup$ – Kuba Jan 18 at 15:13
2
$\begingroup$

I found this clunky workaround:

file = NotebookOpen[filename];
FrontEndExecute[FrontEndToken[file, "SelectAll"]]
FrontEndExecute[FrontEndToken[file, "Evaluate"]]
$\endgroup$
  • 1
    $\begingroup$ It should be noted that this workaround behaves very differently to NotebookEvaluate in a few aspects: NotebookEvaluate evaluates the notebook and waits until it is done, while your method simply enqueues it for evaluation. (Also, the line numbers are different) $\endgroup$ – Lukas Lang May 10 at 8:01

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.