How to check whether the FrontEnd considers evaluation still running?
Asked Answered
A

2

1

Is there a way to check programmatically whether the FrontEnd considers evaluation still running? Or even better: is there a way to check whether the FrontEnd has some pending inputs to be sent to the kernel?

P.S. This question has arisen from previous question.

EDIT

When evaluating a Cell in the FrontEnd we usually create a queue of inputs for the kernel.

I need a function that will return True if the FrontEnd has sent to the kernel the last input of the queue of inputs from the EvaluationNotebook[]. Or in other words I need a function that returns True if this current input is the last input of the queue of inputs generated by the FrontEnd.

Advance answered 13/4, 2011 at 0:58 Comment(0)
N
2

This should work. Of course, you have to run it in a different kernel than the one that is performing the evaluation you want to check for.

NotebookEvaluatingQ[nb_] := (
 SelectionMove[nb, All, Notebook];
 Or @@ Map["Evaluating" /. # &, Developer`CellInformation[nb]]
)
Network answered 15/4, 2011 at 4:55 Comment(4)
+1 for pointing out Developer`CellInformation! But isn't it too expensive to run a separate kernel for such a tiny task?Advance
A kernel with only this definition shouldn't be very expensive. "A function that will return True..." would have to get evaluated on the pre-emptive link to the original kernel to return before the queued evaluation does. This would probably have to happen via a MathLink` function, but I'm not sure how.Network
It would be very interesting to learn how to make a pre-emptive link. At this moment I know only that such links are possible but nothing on how one can make them.Advance
Both a pre-emptive link and a queued link exist between every kernel and FE since version 6. The pre-emptive link is used for dynamic evaluations and button evaluations when the button's Method option is set to "Preemptive". It's possible some FrontEndToken construct could manage to get this information and return before the evaluation(s) you want to check, but I don't know how. I recommend using a second kernel for anything like this.Network
B
0

Obviously, it's best to set things up before hand using a tool like Monitor. For example,

Monitor[
  Do[Pause[6], {i, 10}],
i]

will allow you to observe the progress of the index variable i. If you haven't set things up before hand, you might be able to do something using the "Interrupt Evaluation" button under the Evaluation menu. For example, try the following:

Do[Pause[6], {i, 10}]

Now, wait six or more seconds and then select "Interrupt Evaluation". You can then examine the state of i to see how far along it is. You resume evaluation using Continue under "Debugger Controls".

Bandsman answered 13/4, 2011 at 3:40 Comment(6)
@Mark I need programmatic control, not visual. I need a function that will return True if the FrontEnd has sent to the kernel the last input of the queue of inputs (when evaluating a Cell we usually create a queue of inputs for the kernel) from the EvaluationNotebook[].Advance
@Alexey I would love to know what you are working on that calls for all the obscure functionality you have been asking about recently.Cautious
This should be possible because there is PrintTemporary that behaves in similar way: it deletes the printed Cell after finishing the evaluation of the current input cell, not after finishing the evaluation of the current input line as it is stated in the Documentation.Advance
@Cautious I have given already the link to the whole problem I am trying to solve in this question. I need that for my MathLink program that I am developing since that question.Advance
@Alexey so this all relates to "Executing code in v.5.2 kernel from within v.7.01" is that correct?Cautious
@Cautious Yes, that is correct. In that function I wish to be able to abort full sequence of evaluations by pressing a key. But I do not want to quit the master kernel. That function should just terminate slave kernel and stop evaluation of the EvaluationNotebook[] in the master kernel after a user has pressed Alt+"." (or another keyboard combination if it easier to implement).Advance

© 2022 - 2024 — McMap. All rights reserved.