2
$\begingroup$

While developing, I would sometimes like to stop evaluation of selected cells at a certain point. The following example nearly seems to work, but repeated runs of Ctrl+A, Enter reveal something sticking in memory. Is there a good way break out of the evaluation queue?

Print["1"]

Print["2"]

FrontEndExecute@FrontEndToken["EvaluatorAbort"]

Print["3"]

Print["4"]

Example of the problem:

On the fourth repetition (on this occasion) of Ctrl+A, Enter the first cell does not evaluate.

enter image description here

$\endgroup$

1 Answer 1

3
$\begingroup$

As far I can tell the erratic behavior you report is only produced by the first cell in the notebook. For example, with

1 + 1
2 + 2
Print[1]
FrontEndExecute@FrontEndToken["EvaluatorAbort"]
Print[2]
Print[3]

the result of 1 + 1 behaves erratically under repeated evaluation of the whole expression sequence, but the result of 2 + 2 is always OK. I suggest you put a "don't care" expression into the first notebook cell as s work-around.

Edit

Since using "EvaluatorAbort" is unreliable, perhaps the following will be more satisfactory:

Print[1]
FrontEndExecute@FrontEndToken["EvaluatorQuit"]
Print[2]
Print[3]

It seems to work reliably, but incurs the extra overhead of a "Do you really want to ..." dialog and the of time needed to restart the kernel.

$\endgroup$
4
  • $\begingroup$ Thanks, but that still not great. After the abort any cell might be chosen for evaluation, with no telling whether it will evaluate or not. $\endgroup$ Jun 28, 2013 at 15:01
  • $\begingroup$ @ChrisDegnen. Don't understand your comment. Suggest you make it as edit to your question with an example of how it impacts your problem. $\endgroup$
    – m_goldberg
    Jun 28, 2013 at 15:05
  • $\begingroup$ ... for instance, after evaluating the notebook with Ctrl+A, Enter the next cell I want to evaluate could be Print[3], but it may or may not evaluate. $\endgroup$ Jun 28, 2013 at 16:00
  • 1
    $\begingroup$ @ChrisDegnen. I think I see what you are getting at now. However, if the cell you attempt to evaluate after the abort fails to evaluate the first time, it seems to always evaluate on a second try. However, I would agree that FrontEndExecute@FrontEndToken[EvaluatorAbort] appears to leave the kernel in a strange state. $\endgroup$
    – m_goldberg
    Jun 28, 2013 at 16:07

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.