Skip to main content
1 of 4
Kvothe
  • 4.8k
  • 11
  • 32

Aborting any computation that takes too long

One of the biggest annoyances in Mathematica is that it will often hang up without any way to abort (i.e. Alt + . or other methods can't stop the computation). Is there a way to prevent this? I am basically looking for a version of TimeConstrained that actually works. The problem seems to come from a kernel that gets stuck computing and does not check for an abort signal, see Why doesn't Mathematica abort evaluation when I tell it to?. Could we improve on TimeConstrained so that it actually works? I am no expert in these things but might it be possible to start a new parallel kernel and evaluate the expression there. The main kernel (or another parallel kernel) might than be able to kill the parallel kernel if it gets stuck (it could use its own absolute clock so there is basically no need for any feedback from the kernel that got stuck).

Having such a function improvedTimeConstrained would have many advantages over simply killing the main kernel and starting over. For example it would allow code of the form:

improvedTimeConstrained[PossiblyTooExpensiveComputation, 10, CheaperApproximationOfTheComputation]
Kvothe
  • 4.8k
  • 11
  • 32