4

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

Ajasja
  • 13,634
  • 2
  • 46
  • 104
gogoolplex
  • 688
  • 5
  • 12

1 Answers1

11

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.

Heike
  • 35,858
  • 3
  • 108
  • 157