1
$\begingroup$

I am displaying a progress bar in my notebook like this:

(* prepare global variables for dynamic progress bar ... *)
messages = {{"initial message"}};       (* further messages will be appended to it *)
count = 0;
maxCount = 1;  (* initial value>0. It will later be be set to the maximum which count shall actually reach *)
dynAnzeige =   (* dynAnzeige is another global variable *)
Column[{Dynamic[count]
 , Pane[ProgressIndicator[
       Dynamic[count]
     , {0, Dynamic[maxCount]}
     ] (* ProgressIndicator *)
   ] (* Pane *)
 , Dynamic[TextGrid[messages]] 
 }
]; (* Column *)
(*                                         *)
(* application for lengthy computation ... *)
PrintTemporary[Dynamic[dynAnzeige]];  (* a semicolon is allowed with PrintTemporary *)
maxCount = 4;
(* read data from file and set maxCount to number of lines read... *)
For[count = 1, count <= maxCount (* For loop to process data *)
, AppendTo[messages
  , {"waiting " <> ToString[60 + count] <> " seconds."}
  ];
  Print[count]; Pause[60 + count];   (* in my application lengthy processing happen here *)
  count++
]; (* For loop to process data *)
Print["finished!"];
Pause[1];

Of course some real computations are done instead of the Pause commands. In some instances, my computations call external programs through Run[“external program …”]; As a rule of the thumb, the external computations take typically 1 minute or a bit longer. In these cases, I see error messages like this:

The kernel is not responding to a dynamic evaluation. You can either choose to abort and restart the kernel or continue waiting. Dynamic updating can be re-enabled using the Dynamic Update Enabled command in the evaluation menu.

Once such a message appears, the following calculation goes entirely wrong. However, if Run[“external program …”]; is outside of the section where PrintTemporary[Dynamic[dynAnzeige]]; is active, my code works.

  • How can I temporarily pause the update of Dynamic[dynAnzeige] so that the kernel doesn't try to advance the progress bar while the external program is running,
  • what would I need to write into my code afterwards so that the progress bar is then updated again? Before pausing Dynamic[dynAnzeige] I could tell about running an external program through the variable message. The whole progress bar should then remain as it is, without the progress bar moving.

Afterwards I could indicate in message that the external program is finished and start the dynamic update again. It is clear: the kernel has no knowledge about progress of the external program and cannot display the progress of it. But afterwards it should be able to do so again for my Mathematica code.

How do you do this programmatically?

$\endgroup$
1
  • $\begingroup$ Have you seen DynamicUpdating? Example from docs: Style[Dynamic[...], DynamicUpdating -> Dynamic[updating]]. $\endgroup$
    – Michael E2
    Jan 22, 2022 at 18:57

1 Answer 1

2
$\begingroup$

The hint to temporarily block Dynamic updating is right: Bracket Run commands which run an external program like this:

Style[Dynamic[$Version], DynamicUpdating->False];
exitcode = Run["*external program with its parameters*"];
Style[Dynamic[$Version], DynamicUpdating->True];

This worked for me.

$\endgroup$

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.