Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 8000@127.0.0.1,8001@127.0.0.1 -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["8000@127.0.0.1,8001@127.0.0.1",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["8000@127.0.0.1,8001@127.0.0.1", 58, 1]], 
                    ShowStringCharacters -> True, NumberMarks -> True], 
           FrontEndObject[LinkObject["8000@127.0.0.1,8001@127.0.0.1",\
             58, 1]], Editable -> True, AutoDelete -> True]], 
         FrameMargins -> {{4, 5}, {4, 4}}], -FrontEndObject-, 
        Editable -> False]]  
    
  6. Evaluate 2+2 in the notebook and

    link=LinkConnect["8000@127.0.0.1,8001@127.0.0.1",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?

share|improve this question
    
I haven't done this; but out of curiosity: why do you need it? –  Szabolcs Sep 11 '13 at 23:27
    
@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. –  ybeltukov Sep 11 '13 at 23:46
    
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. –  Szabolcs Sep 11 '13 at 23:51
    
@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 :) –  ybeltukov Sep 12 '13 at 0:01

1 Answer 1

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.

share|improve this answer
    
Thanks! It works like a charm. #1 is really solved. –  ybeltukov Sep 12 '13 at 19:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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