mercurial/commands.py
changeset 1840 d17f19d84fd3
parent 1839 876e4e6ad82b
parent 1837 6f67a4c93493
child 1847 94498a262d15
child 1848 bb70ffebe77b
--- a/mercurial/commands.py	Mon Mar 06 17:47:41 2006 +0100
+++ b/mercurial/commands.py	Mon Mar 06 17:53:11 2006 +0100
@@ -2863,27 +2863,30 @@
             else:
                 d = lambda: func(u, *args, **cmdoptions)
 
-            if options['profile']:
-                import hotshot, hotshot.stats
-                prof = hotshot.Profile("hg.prof")
-                try:
+            try:
+                if options['profile']:
+                    import hotshot, hotshot.stats
+                    prof = hotshot.Profile("hg.prof")
                     try:
-                        return prof.runcall(d)
-                    except:
                         try:
-                            u.warn(_('exception raised - generating profile '
-                                     'anyway\n'))
+                            return prof.runcall(d)
                         except:
-                            pass
-                        raise
-                finally:
-                    prof.close()
-                    stats = hotshot.stats.load("hg.prof")
-                    stats.strip_dirs()
-                    stats.sort_stats('time', 'calls')
-                    stats.print_stats(40)
-            else:
-                return d()
+                            try:
+                                u.warn(_('exception raised - generating '
+                                         'profile anyway\n'))
+                            except:
+                                pass
+                            raise
+                    finally:
+                        prof.close()
+                        stats = hotshot.stats.load("hg.prof")
+                        stats.strip_dirs()
+                        stats.sort_stats('time', 'calls')
+                        stats.print_stats(40)
+                else:
+                    return d()
+            finally:
+                u.flush()
         except:
             # enter the debugger when we hit an exception
             if options['debugger']: