# HG changeset patch
# User Vadim Gelfer <vadim.gelfer@gmail.com>
# Date 2006-03-06 16:35:15
# Node ID 6f67a4c93493ea07d3756aab20c341d2b03edbf8
# Parent  cd5c1db2132a2c9a3b28cba6fb909dab4619c321

make ui flush output.  this makes error happen if printing to /dev/full.
before this change, error happened with some pythons, but not others.
now always happens.
fixes issue 155.


diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2860,27 +2860,30 @@ def dispatch(args):
             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']:
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -132,6 +132,12 @@ class ui(object):
         for a in args:
             sys.stderr.write(str(a))
 
+    def flush(self):
+        try:
+            sys.stdout.flush()
+        finally:
+            sys.stderr.flush()
+
     def readline(self):
         return sys.stdin.readline()[:-1]
     def prompt(self, msg, pat, default="y"):