开发者

How to check whether the FrontEnd considers evaluation still running?

开发者 https://www.devze.com 2023-02-25 16:44 出处:网络
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

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 f开发者_如何转开发unction 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.


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]]
)


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".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号