4
$\begingroup$

I have two notebooks open, one has a dynamic expression running (a simple clock)

Dynamic[{d, h, m, s} = 
  List @@ DateDifference[Now, 
     DateObject[{2015, 5, 18}], {"Day", "Hour", "Minute", 
      "Second"}][[1]];
   Grid[Transpose @ {{"d", d}, {"h", h}, {"m", m}, {"s", Round@s}}, 
       Alignment -> Left], UpdateInterval -> 1]

And while this is running, it interferes strongly with the Dynamic expression in my other notebook, even when the notebook is offscreen or minimized. Is there any safeguard for these dynamics bringing the frontend to a crawl?

$\endgroup$
4
  • $\begingroup$ Launch the notebooks in separate kernels running on separate cores (assuming you have a multi-core machine) with LaunchKernels[2]. $\endgroup$ Apr 7, 2015 at 17:06
  • 3
    $\begingroup$ Wrap both dynamic expressions with DynamicModule and localize your variables there. $\endgroup$ Apr 7, 2015 at 19:40
  • $\begingroup$ @DavidG.Stork What is the relation between kernels and dynamics, I thought that for Dynamic's the FE was the bottleneck. $\endgroup$
    – M.R.
    Apr 7, 2015 at 20:17
  • $\begingroup$ @M.R. A Dynamic's front end may or may not be the computational bottleneck, depending upon the algorithms, the complexity of the rendering, and so forth. $\endgroup$ Apr 7, 2015 at 20:25

1 Answer 1

3
$\begingroup$

You may consider moving the variables used for the dynamic clock into a dedicated context

Dynamic[{clock`d, clock`h, clock`m, clock`s} = 
  List @@ DateDifference[Now, 
     DateObject[{2015, 5, 18}], {"Day", "Hour", "Minute", 
      "Second"}][[1]];

Grid[Transpose@{{"d", clock`d}, {"h", clock`h}, {"m", clock`m}, {"s",
      Round@clock`s}}, Alignment -> Left], UpdateInterval -> 1]

When creating a variable by indicating a new context in the form context`variable a new context will be created along with the variable. This can be verified using Contexts[]

$\endgroup$
1
  • $\begingroup$ @Karsten 7 thx for the formatting,,,,penguins not very smart :) $\endgroup$
    – penguin77
    Apr 8, 2015 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.