Message Boards Message Boards

[✓] Call a slow running function from dynamic interface?


I have a custom function which demands much time (maybe several hours) to calculate result. I wanted to call the function from dynamic interface, where I define input variables and call the function by button. I found that the function outputs results differently from the case, when I call it without interface. And calculation is aborted after short time without any error message. The function is outside the interface. I tried different methods to force the function to run till end of calculation but in vain. I made a simple example to show the problem.

(*Example of function with long time of execution*)

long[max_] := Block[{ max1},
  max1 = max;
  Print["max=", max1];
  Table[Print[i, " ", ProgressIndicator[i, {0, max}]]; Pause[2],
   {i, 1, max1}];

(*Call of long[max]*)

The function runs till end.

(*Call of the same function from interface*)
    Row[{Control[{n, {3, 5, 8, 10, 20}}]}],
    Button["Start", long[n]]}]

The function terminates after 6 sec of running

Is it possibility to call slow function from dynamic interface?

POSTED BY: Ivan Siahlo
4 months ago

You need to add Method -> "Queued" to your Button. Otherwise it times out after 5 seconds.

POSTED BY: Gustavo Delfino
4 months ago

Thank you very march. It works.

POSTED BY: Ivan Siahlo
4 months ago

Group Abstract Group Abstract