From b5672f1565c8511c0efb4fe9ba832fad5cd05fd0 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Sat, 10 Apr 2010 19:24:47 -0700 Subject: [PATCH] Cleaning up read/monitor/interrupt. Now you don't need to specify a default read count. Now, by default, we print the pid out in sendCmd() which allows us to snarf it later and set lastPid correctly. Now, we wrap os.kill() in a try block, so that if the process is already gone we don't get an exception. --- mininet/node.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mininet/node.py b/mininet/node.py index 6dfebff..c1615d3 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -109,7 +109,7 @@ class Node( object ): self.shell = None # Subshell I/O, commands and control - def read( self, bytes ): + def read( self, bytes=1024 ): """Buffered read from node, non-blocking. bytes: maximum number of bytes to return""" count = len( self.readbuf ) @@ -154,7 +154,7 @@ class Node( object ): if len( self.readbuf ) == 0: self.pollOut.poll() - def sendCmd( self, cmd, printPid=False ): + def sendCmd( self, cmd, printPid=True ): """Send a command, followed by a command to echo a sentinel, and return without waiting for the command to complete.""" assert not self.waiting @@ -175,7 +175,10 @@ class Node( object ): def sendInt( self, sig=signal.SIGINT ): "Interrupt running command." if self.lastPid: - os.kill( self.lastPid, sig ) + try: + os.kill( self.lastPid, sig ) + except e, Exception: + pass def monitor( self ): """Monitor and return the output of a command.