8
$\begingroup$

FrontEndExecute[FrontEndToken["EvaluatorAbort"]] is equivalent of the menu item: Evaluation >> Abort.

It works with signals as explained in Difference between Evaluation>>Quit Kernel and Quit[].

One can use it, from preemptive link, to abort e.g. a loop:

Button["Abort", FrontEndExecute[FrontEndToken["EvaluatorAbort"]], 
       Method -> "Preemptive"]
While @ True
$Aborted (*after click*)

Question: I can't do this from ScheduledTasks, why?

I was expecting here that after first Print the loop will be broken (you would see cell bracket stop being highlighted, but it is still bold)

RunScheduledTask[
 Print[DateString[]];
 FrontEndExecute[FrontEndToken["EvaluatorAbort"]];
 ,
 {1, 3}, 5]
While @ True

Few notes:

ScheduledTasks are returned by Service Link:

enter image description here

but I don't know why this matters.

Related topics:

Aborting from inside a ScheduledTask

Installing LinkSnooper on Windows

What are the purposes of functions in FrontEnd` context


cross posted on Wolfram Community

$\endgroup$
2
  • $\begingroup$ It's a bit late here, but from the top of my head I know only one reason for that: the kernel simply ignores this signal when it comes over the service link. Why the kernel does it? I have no clue at the moment. $\endgroup$
    – halirutan
    Feb 28, 2015 at 3:27
  • $\begingroup$ Btw, over the service link was written badly, because it is a signal, but it seems it has something to do that it is evaluated in the scheduled task. $\endgroup$
    – halirutan
    Feb 28, 2015 at 3:37

1 Answer 1

5
$\begingroup$

Pulling the Linksnooper out of your pocket was the right call and I guess you would have found this yourself soon. Please don't ask me about the why, because I don't know it. Additionally, I have only tested this on Linux.

Let's create a small test using the "EvaluatorAbort" FE token

Button["Abort", FrontEndExecute[FrontEndToken["EvaluatorAbort"]]]

You need to know two things: This command is send to the kernel for evaluation. The kernel sees the FrontEndExecute and sends the FE token back to the FE. The FE is now expected to send the Kernel a signal to abort. How the last part works is kind of explained in the answer you already referred to.

The big question is, will the FE always send signal 3 if I hit the button. Unfortunately, this seems not to be the case, because when I press it without any computation running the LinkSnooper shows only

enter image description here

When I run a While[True] before pressing the button on the other hand, I see the following

enter image description here

It seems that the FE has the final word in whether or not it likes to do what I asked it to do. Now, it seems that when you use RunScheduledTask, the FE ignores this all the time, even if a evaluation is running. There is not much I can do about this.

On the other hand, we do know that all communication is done through MathLink or as we're ordered to call it these days Wolfram Symbolic Transfer Protocol aka WSTP. Therefore, I tried to circumvent the FrontEndExecute by writing the token directly to the FE link.

At least on my machine, this was successful and the loop is aborted:

RunScheduledTask[Print[DateString[]];
 LinkWrite[First[$FrontEnd], FrontEndToken["EvaluatorAbort"]];, {1, 3}, 5]
While@True
$\endgroup$
0

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.