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


Groups > comp.soft-sys.math.mathematica > #5310

Re: How to catch interrupts generated by TimeConstrained?

From Peter Pein <petsie@dordos.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: How to catch interrupts generated by TimeConstrained?
Date 2011-10-01 07:12 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j66ehj$hfd$1@smc.vnet.net> (permalink)
References <j6123m$m2q$1@smc.vnet.net>

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

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

csiph-web