I am following this answer to evaluate certain cells in a separate kernel. I have created a separate kernel called K2
and have the following MWE:
myvar = 1;
DistributeDefinitions[myvar]
{myvar}
Which - I believe - makes the definition of myvar
available in all kernels.
Now I am running e.g.
CellPrint@Cell[BoxData[MakeBoxes[Defer[1 + 1]]], "Input", Evaluator -> "K2"]
which produces a cell
1+1
that can be evaluated (in kernel K2
) and yields 2
(unsurprisingly). So far, so good.
Now, if I run
CellPrint@Cell[BoxData[MakeBoxes[Defer[myvar]]], "Input", Evaluator -> "K2"]
a cell
myvar
is created. But evaluating it still yields only myvar
rather than 1
. (The same holds if I omit the Defer
).
I believe I am misunderstanding the concept of separate kernel evaluation? Ultimately, I want to send not only a variable, but a custom function to K2
.