Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
1  
have you tried it? –  belisarius Dec 6 '13 at 15:57
1  
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. –  Joel Klein Dec 6 '13 at 22:27
    
My guess/expectation is that it would only abort whatever is being evaluated in the task. What is the answer? –  Mike Honeychurch Dec 6 '13 at 22:32
1  
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? –  Szabolcs Dec 7 '13 at 0:48
1  
It is strongly recommended to self answer, the more that your answer would be the most reliable here :) –  Kuba Dec 7 '13 at 9:44

1 Answer 1

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:

RunScheduledTask[
 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:"]; 
Do[
   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.

share|improve this answer
    
I have included some clarification, hope you don't mind! –  István Zachar Dec 10 '13 at 20:51
    
That's great, thank you! –  Joel Klein Dec 10 '13 at 22:21
    
@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? –  Alexey Popkov Dec 13 '13 at 19:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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