Message Boards Message Boards


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

Posted 1 year ago
2 Replies
2 Total Likes

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?

2 Replies

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

Thank you very march. It works.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract