3
$\begingroup$

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):

  1. 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.

  2. 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).

  3. 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 *)
    
  4. Now in the notebook you see that 2+2=4 :)

    Disconnect from the kernel:

    links = {$ParentLink, MathLink`$ServiceLink, MathLink`$PreemptiveLink}; 
        $ParentLink = Null; LinkClose /@ links;
    
  5. In the terminal evaluate y=x^2 one more time

    In[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 empty

    In[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]]  
    
  6. Evaluate 2+2 in the notebook and

    link=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?

$\endgroup$
4
  • $\begingroup$ I haven't done this; but out of curiosity: why do you need it? $\endgroup$
    – Szabolcs
    Sep 11, 2013 at 23:27
  • $\begingroup$ @Szabolcs It is related to the connection to the remote machine and my this post. I've also read your question but I want different: just connect, do some preliminary evaluations, run a big task, disconnect and reconnect after several days when calculations end. $\endgroup$
    – ybeltukov
    Sep 11, 2013 at 23:46
  • $\begingroup$ Personally I gave up on that. Now I just use GNU screen. I'm curious to see if you manage to work out a solution to your problem. I see you already found GetFEKernelInit.tr and related files. That was the only thing I could have added. $\endgroup$
    – Szabolcs
    Sep 11, 2013 at 23:51
  • $\begingroup$ @Szabolcs I already use it (now I just ignore warnings). I'm going to put the calculations and go to sleep. Tomorrow I reconnect from work and check the results :) $\endgroup$
    – ybeltukov
    Sep 12, 2013 at 0:01

1 Answer 1

5
$\begingroup$

The formatting you're seeing on the command-line is caused as a result of settings the FE makes to the "stdout" stream. Internally, the FE calls this function:

FE`SetResultForm[FE`form_] :=
    SetOptions["stdout", FormatType -> FE`form];

with the argument for form being whatever the default output format should be. This setting doesn't get reset when the kernel disconnects from the FE, but it's easy enough for you to do call this directly:

SetOptions["stdout", FormatType->OutputForm]

That's your problem #1 solved.

I wasn't able to reproduce your second problem, but if the problem is just the warning, then surely you could shut the warning off. You can't bracket the FE's evaluation of the code in FEKernelInit.tr directly using Quiet, but you could issue an Off command in the terminal followed by an On command in the FE.

$\endgroup$
1
  • $\begingroup$ Thanks! It works like a charm. #1 is really solved. $\endgroup$
    – ybeltukov
    Sep 12, 2013 at 19:21

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.