Re: Q: LinkInterrupt[link]
- To: mathgroup at smc.vnet.net
- Subject: [mg16892] Re: Q: LinkInterrupt[link]
- From: Jens-Peer Kuska <v-jkuska>
- Date: Mon, 5 Apr 1999 02:24:27 -0400
- Organization: Wolfram Research, Inc.
- References: <7e1c37$bb0@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Tobias, at first, I can't not verify this behaviour. On my Linux box with Mathematica 3.0.1 the link does not break, also a SPARC/Solaris and a SGI both Mathematica 3.0.2 work correct when I read the second packet. Since you don't write what operating system and what Mathamtica version you are using it is impossible to find out what goes wrong. But at least you have to read two packets after the LinkInterrupt[l] command In[39]:= LinkRead[l] Out[39]= MenuPacket[0, Interrupt> ] In[40]:= LinkRead[l] Out[40]= TextPacket[ > Your options are: ] abort (or a) to abort current calculation continue (or c) to continue exit (or quit) to exit Mathematica inspect (or i) to enter an interactive dialog show (or s) to show current operation (and then continue) trace (or t) to show all operations and you must read the second one before you are writing to the link with LinkWrite[l,TextPacket["t"]] When you don't read the second packet you produce a deadlock and you may mixup the communication buffer. It is quit natural that the link breaks in this situation. Regards Jens tobiasoed at my-dejanews.com wrote: > > Has one of you ever tried the example using LinkInterrupt[] p. 659 of The > Book? It goes like this: > > (* launch a new mathematica kernel and communicate with it through mathlink *) > > In[1]:= l=LinkCreate["math -mathlink -linkmode > ParentConnect",LinkMode->Launch] Out[1]= LinkObject[math -mathlink -linkmode > ParentConnect, 1, 1] > > (* read the first prompt from the link *) > > In[2]:= LinkRead[l] > Out[2]= InputNamePacket[In[1]:= ] > > (* let the new kernel do some lengthly calculation *) > > In[3]:= LinkWrite[l,EnterTextPacket["FactorInteger[2^177-1]"]] > > (* interrupt this calculation *) > > In[4]:= LinkInterrupt[l] > > (* read the interrupt menu prompt from the link *) > > In[5]:= LinkRead[l] > Out[5]= MenuPacket[1, Interrupt> ] > > Here the example stops. > Lets try to abort the calculation > > In[6]:= LinkWrite[l,TextPacket["a"]] > > (* read the output and the next prompt *) > > In[7]:= LinkRead[l] > Out[7]= OutputNamePacket[Out[1]= ] > > In[8]:= LinkRead[l] > Out[8]= ReturnTextPacket[$Aborted] > > In[9]:= LinkRead[l] > Out[9]= InputNamePacket[In[2]:= ] > > Everything works as one would expect. > Let's now try to trace a caluculation instead of aborting it: > > (* start the lenghly calculation again and interrupt it *) > > In[10]:= LinkWrite[l,EnterTextPacket["FactorInteger[2^177-1]"]] > > In[11]:= LinkInterrupt[l] > > In[12]:= LinkRead[l] > > Out[12]= MenuPacket[1, Interrupt> ] > > (* trace the calculation *) > > In[13]:= LinkWrite[l,TextPacket["t"]] > > (* read the output *) > > In[14]:= LinkRead[l] > Out[14]= TextPacket[long multiplication] > > In[15]:= LinkRead[l] > Out[15]= TextPacket[long multiplication] > > In[16]:= LinkRead[l] > > LinkObject::linkd: > LinkObject[math -mathlink -linkmode ParentConnect, 1, 1] > is closed; the connection is dead. > > Out[16]= $Failed > > Why does the link die? what do I do wrong here ? > Tobias > > -----------== Posted via Deja News, The Discussion Network ==---------- > http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own