From c2cc1aacf6be0dd5f74968065b55fca9b534d37f Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Wed, 24 Mar 2010 17:17:24 -0700 Subject: [PATCH] Attempt to handle interrupts in the middle of CLI commands. --- mininet/cli.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/mininet/cli.py b/mininet/cli.py index 0e77f28..a6440fb 100644 --- a/mininet/cli.py +++ b/mininet/cli.py @@ -35,6 +35,17 @@ from cmd import Cmd from mininet.log import info, output, error + +def waitForNode( node ): + "Wait for a node to finish, and print its output." + while node.waiting: + try: + data = node.monitor() + info( '%s' % data ) + except KeyboardInterrupt: + node.sendInt() + + class CLI( Cmd ): "Simple command-line interface to talk to nodes." @@ -54,6 +65,8 @@ class CLI( Cmd ): break except KeyboardInterrupt: info( 'Interrupt\n' ) + for node in self.nodelist: + waitForNode( node ) def emptyline( self ): "Don't repeat last command when you hit return." @@ -210,12 +223,7 @@ class CLI( Cmd ): rest = ' '.join( rest ) # Run cmd on node: node.sendCmd( rest, printPid=True ) - while node.waiting: - try: - data = node.monitor() - info( '%s' % data ) - except KeyboardInterrupt: - node.sendInt() + waitForNode( node ) else: self.stdout.write( '*** Unknown syntax: %s\n' % line )