I'm connecting to and disconnecting from the kernel but I'm doing something wrong. I crash the text formatting in the terminal and got some warnings. There are some instructions to connecting to the kernel, but I almost didn't find anything about the disconnecting from the kernel. This question is related to connection to the remote machine and particularly to my this answer.
I'm doing the following (based on this instructions):
Open terminal and run
math
Mathematica 9.0 for Linux x86 (64-bit) Copyright 1988-2013 Wolfram Research, Inc. In[1]:= y=x^2 2 Out[1]= x
OK, it works fine.
Open regular Mathematica.
Create a new kernel configuration (Evaluation menu -> Kernel Configuration Options...)
Select Advanced Options.
Arguments to MLOpen:
-LinkName [email protected],[email protected] -LinkMode Listen -LinkProtocol TCPIP -LinkOptions MLDontInteract -LinkHost 127.0.0.1
Shell command to launch kernel: leave empty (we will do it manually)
Set the notebook's kernel to the one you just set up, and evaluate something (
2+2
).In the terminal evaluate the following:
link=LinkConnect["[email protected],[email protected]",LinkProtocol->"TCPIP"] (* connect to front end link *) $ParentLink = link; (* set the front end link as parent link *)
Now in the notebook you see that 2+2=4 :)
Disconnect from the kernel:
links = {$ParentLink, MathLink`$ServiceLink, MathLink`$PreemptiveLink}; $ParentLink = Null; LinkClose /@ links;
In the terminal evaluate
y=x^2
one more timeIn[8]:= y=x^2 Out[8]= RawBoxes[SuperscriptBox[x, 2]]
It's not what you expect to see. Moreover, you can see that
$FrontEnd
isn`t emptyIn[9]:= $FrontEnd Out[9]= RawBoxes[InterpretationBox[PanelBox[TooltipBox[ C FrontEndObject C, InterpretationBox[StyleBox[FrontEndObject\ [LinkObject["[email protected],[email protected]", 58, 1]], ShowStringCharacters -> True, NumberMarks -> True], FrontEndObject[LinkObject["[email protected],[email protected]",\ 58, 1]], Editable -> True, AutoDelete -> True]], FrameMargins -> {{4, 5}, {4, 4}}], -FrontEndObject-, Editable -> False]]
Evaluate
2+2
in the notebook andlink=LinkConnect["[email protected],[email protected]",LinkProtocol->"TCPIP"] $ParentLink = link;
in the terminal one more time. The notebook is now reconnected to the kernel, but you can see warnings like
SetDelayed::write: Tag UpdateDynamicObjects in UpdateDynamicObjects[] is Protected. >> SetDelayed::write: Tag UpdateDynamicObjectsSynchronous in UpdateDynamicObjectsSynchronous[] is Protected. >>
Except the bad formatting in the terminal and these warnings everything works fine.
The first I can temporary fix by
In[16]:= $Post=TextForm;
Out[16]//TextForm= Null
In[17]:= y=x^2
2
Out[17]//TextForm= x
But it produces annoying //TextForm
.
The messages come from the reevaluation of $InstallationDirectory/SystemFiles/FrontEnd/TextResources/GetFEKernelInit.tr
which contain the following lines
UpdateDynamicObjects[] := (
FrontEnd`Private`changes = Internal`GetTrackChanges[];
If[Length[FrontEnd`Private`changes] =!= 0,
MathLink`CallFrontEnd[FrontEnd`UpdateDynamicObjectsSynchronous[
FrontEnd`Private`changes]]];
)
UpdateDynamicObjectsSynchronous[] :=
MathLink`CallFrontEnd[FrontEnd`UpdateDynamicObjectsSynchronous[
Internal`GetTrackChanges[]]];
Do you have any experience with disconnecting from the kernel?