且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查FrontEnd是否认为评估仍在运行?

更新时间:2023-12-05 09:22:22

这应该有效.当然,您必须在与要执行评估的内核不同的内核中运行它.

NotebookEvaluatingQ[nb_] := (
 SelectionMove[nb, All, Notebook];
 Or @@ Map["Evaluating" /. # &, Developer`CellInformation[nb]]
)

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.

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