Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5276 > unrolled thread

How to catch interrupts generated by TimeConstrained?

Started byAlexey Popkov <lehin.p@gmail.com>
First post2011-09-29 06:09 +0000
Last post2011-10-01 07:12 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  How to catch interrupts generated by TimeConstrained? Alexey Popkov <lehin.p@gmail.com> - 2011-09-29 06:09 +0000
    Re: How to catch interrupts generated by TimeConstrained? Peter Pein <petsie@dordos.net> - 2011-10-01 07:12 +0000

#5276 — How to catch interrupts generated by TimeConstrained?

FromAlexey Popkov <lehin.p@gmail.com>
Date2011-09-29 06:09 +0000
SubjectHow to catch interrupts generated by TimeConstrained?
Message-ID<j6123m$m2q$1@smc.vnet.net>
Hello,

Mathematica has the CheckAbort function which allows to catch and
handle user-generated and programmatic Aborts. But it does not allow
to catch interrupts generated by such functions as TimeConstrained and
MemoryConstrained:

TimeConstrained[CheckAbort[Pause[100], Print["From CheckAbort"]], 1]

(does not print "From CheckAbort").

Is there a way to catch such interrupts in Mathematica?

Alexey

P.S. The reason why I need this is that I have a function that creates
MathLink objects which must be closed in the case of any interrupts or
aborts but not in other cases.

[toc] | [next] | [standalone]


#5310

FromPeter Pein <petsie@dordos.net>
Date2011-10-01 07:12 +0000
Message-ID<j66ehj$hfd$1@smc.vnet.net>
In reply to#5276
Am 29.09.2011 08:09, schrieb Alexey Popkov:
> Hello,
> 
> Mathematica has the CheckAbort function which allows to catch and
> handle user-generated and programmatic Aborts. But it does not allow
> to catch interrupts generated by such functions as TimeConstrained and
> MemoryConstrained:
> 
> TimeConstrained[CheckAbort[Pause[100], Print["From CheckAbort"]], 1]
> 
> (does not print "From CheckAbort").
> 
> Is there a way to catch such interrupts in Mathematica?
> 
> Alexey
> 
> P.S. The reason why I need this is that I have a function that creates
> MathLink objects which must be closed in the case of any interrupts or
> aborts but not in other cases.
> 
> 
Well if CheckAbort is needed for other reasons (e.g. impatient user),
try the workaround

If[CheckAbort[
     TimeConstrained[Beep[]; Pause[2], #], $Aborted] === $Aborted,
   "closing links...", "keeping links open"] & /@ {1, 3}

if you do not touch the keyboard while running this toy example it will
end up with {"closing links...", "keeping links open"}

and if you abort after the second beep using <Alt>. or whatever is the
abort-shortcut on your system then it will return

{"closing links...", "closing links..."}

hth,
Peter

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web