Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer 1

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.

share|improve this answer
    
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. –  Chris Degnen Jun 28 '13 at 15:01
    
@ChrisDegnen. Don't understand your comment. Suggest you make it as edit to your question with an example of how it impacts your problem. –  m_goldberg Jun 28 '13 at 15:05
    
... 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. –  Chris Degnen Jun 28 '13 at 16:00
1  
@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. –  m_goldberg Jun 28 '13 at 16:07
add comment

Your Answer

 
discard

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.