1
$\begingroup$

I have a function f, over whose source code I have no control. Is there a way for me to decorate f so that if the evaluation time on an input exceeds, say, five seconds, the returned value is something like Missing["EvaluationThresholdReached"]?

$\endgroup$
4
$\begingroup$

How about

TimeConstrained[f[whatever],5,Missing["EvaluationThresholdReached"]]

?

$\endgroup$
1
  • $\begingroup$ Excellent. I didn't know about this function. Thank you. $\endgroup$ Sep 5 '19 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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