Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Imagine I provide some random input to function like FindInstance[], and I observe that, despite the existence of good solutions, the function will, with some probability, indefinitely evaluate without success. For an example, please see my earlier question: Why is FindInstance failing when I relax a set of constraints?

Can I somehow force the function to return, say, an empty list {} after some time $T$ has passed?

share|improve this question
Did you check TimeConstraint? – Spawn1701D Apr 22 '13 at 1:11
@Spawn1701D That seems not to work for FindInstance? – Peter Apr 22 '13 at 1:13
@Spawn1701D I'm looking for something I can also wrap around some section of code to force it to restart or quit after some time has passed. – Peter Apr 22 '13 at 1:14
There is also the wrapper/Function variant TimeConstrained. – Spawn1701D Apr 22 '13 at 1:16
@Spawn1701D Yup, that seems to work! – Peter Apr 22 '13 at 1:17
up vote 2 down vote accepted

TimeConstrained[expr, t, failexpr] returns failexpr if the time constraint t is not met.

share|improve this answer

Your Answer


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.