From bda2317d8b31c9a16533490131f3f4263c53e714 Mon Sep 17 00:00:00 2001 From: Brian O'Connor Date: Thu, 25 Jul 2013 19:27:06 -0700 Subject: [PATCH 1/2] Catching exceptions thrown in mn --- bin/mn | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/bin/mn b/bin/mn index bba2353..605c2bc 100755 --- a/bin/mn +++ b/bin/mn @@ -22,7 +22,7 @@ if 'PYTHONPATH' in os.environ: from mininet.clean import cleanup from mininet.cli import CLI -from mininet.log import lg, LEVELS, info +from mininet.log import lg, LEVELS, info, debug, error from mininet.net import Mininet, MininetWithControlNet, VERSION from mininet.node import ( Host, CPULimitedHost, Controller, OVSController, NOX, RemoteController, UserSwitch, OVSKernelSwitch, @@ -278,4 +278,21 @@ class MininetRunner( object ): if __name__ == "__main__": - MininetRunner() + try: + MininetRunner() + except KeyboardInterrupt: + info( "Keyboard Interrupt. Shutting down and cleaning up...") + cleanup() + except Exception: + #Print exception + type_, val_, trace_ = sys.exc_info() + errorMsg = ( "-"*80 + "\n" + + "Caught exception. Cleaning up...\n\n" + + "%s: %s\n" % ( type_.__name__, val_ ) + + "-"*80 + "\n" ) + error( errorMsg ) + # Print stack trace to debug log + import traceback + stackTrace = traceback.format_exc() + debug( stackTrace + "\n" ) + cleanup() From 19bc1df15d3bd6333bfc22cf10701b607d462d54 Mon Sep 17 00:00:00 2001 From: Brian O'Connor Date: Fri, 26 Jul 2013 13:45:56 -0700 Subject: [PATCH 2/2] fixed style error --- bin/mn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/mn b/bin/mn index 605c2bc..91f8bff 100755 --- a/bin/mn +++ b/bin/mn @@ -284,7 +284,7 @@ if __name__ == "__main__": info( "Keyboard Interrupt. Shutting down and cleaning up...") cleanup() except Exception: - #Print exception + # Print exception type_, val_, trace_ = sys.exc_info() errorMsg = ( "-"*80 + "\n" + "Caught exception. Cleaning up...\n\n" +