0
$\begingroup$

For a simple demostration of the behavior, note that the print statements in this expression appear in the Messages window: Column[{Slider[Dynamic[x]], Dynamic[Print[x]; x]}]

This behavior of Dynamic[] is not clear from the documentation that I reviewed, though it is possible/likely that I'm not sufficiently skilled in navigating the documentation.

Additionally, I found that under certain circumstances an error in this expression will cause what seems to be pathological printing behavior, In the following example, (which throws a huge error highlighting and may cause lag on your front end, test with caution. I discovered this using the following (editted into a small working example):

BeginPackage["Test`"];
testDynamic::usage = "";
testFun1::usage = "";
testFun2::usage = "";
Begin["`Private`"]

testDynamic[img_] := Manipulate[
    Module[{controlTable, hm, hm0, out},
        controlTable = {{"(xc, yc)=", xc, yc}, {"(dx,dy)=", dx, dy}};
        hm = testFun1[testFun2[img, {xc, yc}, {dx, dy}]];
    Row[{controlTable // TableForm, hm}]],
  {{xc, 150}, 0, 500, 1}, {{yc, 150}, 0, 300, 1}, {{dx, 50}, 1, 500, 
   1}, {{dy, 50}, 1, 300, 1}]

testFun1[img_] := Module[{}, Print["In testFun1"]; MatrixPlot[img]]

testFun2[arr_, center_List, halfWidths_List] := 
 Module[{dims, bottom, top, right, left, edges, out},
    dims = Dimensions@arr;
  Print["in testFun2"];
    left = Max[1, center[[2]] - halfWidths[[2]]];
    right = Min[dims[[2]], center[[2]] + halfWidths[[2]]];
    bottom = Min[dims[[1]], center[[1]] + halfWidths[[1]]];
    top = Max[1, center[[1]] - halfWidths[[1]]];
    edges = {{top, bottom}, {left, right}};
    out = Take[arr, Sequence @@ edges];
  out]

End[];
EndPackage[];

img = RandomInteger[255, {250, 350}];

testDynamic[img]

The image previewer can be thrown into a error state by dragging the top slider to the right. When that occurs, the Print messages do begin to leak into the Front End.

My first question is admittedly a mostly academic one, since it seems clear that in most situations, this would horrifically clog up the front end. But perhaps others are aware of a case where one might want to brick the front end in this way? Hence my second question, to which i think the answer is "Probably Not"

Related: Printing a Dynamic variable inside Dynamic

EDIT: It seems that the sporadic printing to the Front End instead of the Messages window occurs in the absence of an error when the computation starts causing the front end to lag.

$\endgroup$
3
  • $\begingroup$ So, It appears that the leak to the front end doesn't require an error. $\endgroup$ Commented Apr 11, 2024 at 2:00
  • $\begingroup$ What do you mean by "Print messages do begin to leak into the Front End"? Do you mean error messages or Print? Regardless if they are printed to console or a notebook it is the front end that has to do this. Print and messages go to the console if they are issued from a preemptive evaluation, like regular Dynamic. You can compare it to Column[{Slider[Dynamic[y]], Dynamic[Print[y]; y, SynchronousUpdating -> False]}] which uses asynchronous updating like regular Shift+Enter. $\endgroup$ Commented Apr 11, 2024 at 7:40
  • $\begingroup$ Great point, let me clarify: I meant that the Print messages which normally are printed to the Messages window began to be printed in the EvaluationNotebook like normal. But this "leakage" only occurs when things seem to get bogged down. $\endgroup$ Commented Apr 12, 2024 at 0:15

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.