4
$\begingroup$

I would like to trigger a long calculation inside a dynamic module with a Button. It seems that the evaluation stops without an error-message after some seconds. I made a test outside the a dynamic module:

Clear[res]
Button["run", res = Total[Table[i; Pause[1], {i, 1, 3}]]]

After pressing the button, the result is: 3 Null

Ok but if the calculation takes 6 seconds

Clear[res]
Button["run", res = Total[Table[i; Pause[1], {i, 1, 6}]]]

Then res is not assigned.

Why does it happen and how can it be avoided, also inside a DynamicModule. I would like something like this:

  • Button to start a simulation run

  • Another Button which does some analysis on the simulation results

$\endgroup$

1 Answer 1

11
$\begingroup$

This behaviour is explained in the documentation of Button under Examples > Options > Method. By default, button functions are evaluated on a preemptive link which times out after 5 seconds. To prevent the code from timing out you can set Method -> "Queued" which will run the code on the main link.

$\endgroup$
3
  • 1
    $\begingroup$ You can also directly change the DynamicEvaluationTimeout option value, but that is not recommended - forums.wolfram.com/mathgroup/archive/2010/Apr/msg00490.html $\endgroup$ Jul 2, 2012 at 13:45
  • $\begingroup$ Thanks! That was exactly what I wanted. $\endgroup$
    – gogoolplex
    Jul 2, 2012 at 13:53
  • $\begingroup$ I'm facing the same issue with a SetterBar instead of a Button - Method option does not exist for SetterBar. $\endgroup$ Dec 21, 2018 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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