From 2031c7de5d0ace9861aa6b0e2db18d029defa3c9 Mon Sep 17 00:00:00 2001
From: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Date: Wed, 15 Jan 2014 12:16:24 +0100
Subject: [PATCH] trace: exit silently when stdout pipe is broken

When output is not fully consumed because of piping, eg to `head`,
we get an ugly exception:

 Traceback (most recent call last):
   File "scripts/trace.py", line 274, in <module>
     args.func(args)
   File "scripts/trace.py", line 227, in list_timed
     bt_formatter(t.backtrace),
 IOError: [Errno 32] Broken pipe

Let's ignore it, it's normal condition.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
---
 scripts/trace.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/scripts/trace.py b/scripts/trace.py
index 251f20297..adaa3ecc2 100755
--- a/scripts/trace.py
+++ b/scripts/trace.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 import sys
+import errno
 import argparse
 from osv import trace, debug, prof
 
@@ -163,4 +164,9 @@ if __name__ == "__main__":
     cmd_prof_hit.set_defaults(func=prof_hit)
 
     args = parser.parse_args()
-    args.func(args)
+
+    try:
+        args.func(args)
+    except IOError as e:
+        if e.errno != errno.EPIPE:
+            raise
-- 
GitLab