If you have an Abort[] inside a ScheduledTask expression, what does it abort? The scheduled task evaluation, or any main kernel evaluation that is ongoing?

  • 1
    $\begingroup$ have you tried it? $\endgroup$ – Dr. belisarius Dec 6 '13 at 15:57
  • 1
    $\begingroup$ Yes, and I know the answer. I'm contributing this question which came to me from a Mathematica user because (a) it's not necessarily obvious what it should do and (b) it's not currently documented. $\endgroup$ – Joel Klein Dec 6 '13 at 22:27
  • $\begingroup$ My guess/expectation is that it would only abort whatever is being evaluated in the task. What is the answer? $\endgroup$ – Mike Honeychurch Dec 6 '13 at 22:32
  • 1
    $\begingroup$ I tried and it only aborts the task. An explanation would be nice since you know the internals :-) How does this functionality even work? Does it depend on anything outside of the kernel (e.g. Java)? Are these pre-emptive evaluations (like Button by default)? Is the functionality exactly the same as Internal`Periodicals or different? $\endgroup$ – Szabolcs Dec 7 '13 at 0:48
  • 1
    $\begingroup$ It is strongly recommended to self answer, the more that your answer would be the most reliable here :) $\endgroup$ – Kuba Dec 7 '13 at 9:44

Abort[] inside a scheduled task will abort the rest of the task expression at the given time, not any main evaluation. It will also repeat to evaluate the task (up till the Abort[]) if further time slots are scheduled.

To show this, first start a scheduled task:

 Print[DateString[], " Scheduled task before Abort[]"]; Abort[]; 
 Print[DateString[], " Scheduled task after Abort[]"], {5, 3}, 5]

By itself you can see that the scheduled task expression gets aborted: in the Messages window you will see the "before" Print output, but not the "after".

While this is running, start a long-running evaluation in a cell:

Print["Mersenne primes:"]; 
   With[{n = 2^i - 1, i = i}, 
      If[PrimeQ[n], Print[HoldForm[2^i - 1 == n]]]
   {i, 10^6}

This keeps evaluating even when the scheduled task issues its Abort.

| improve this answer | |
  • $\begingroup$ I have included some clarification, hope you don't mind! $\endgroup$ – István Zachar Dec 10 '13 at 20:51
  • $\begingroup$ That's great, thank you! $\endgroup$ – Joel Klein Dec 10 '13 at 22:21
  • $\begingroup$ @JoelKlein After starting the long-running evaluation I do not see messages from the ScheduledTask no more (I use v. 8.0.4). Why this happens? $\endgroup$ – Alexey Popkov Dec 13 '13 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.