From 8688d98c4d8d43690eaeda47935fae36172079ff Mon Sep 17 00:00:00 2001 From: Vincent Pelletier <vincent@nexedi.com> Date: Thu, 27 Mar 2014 10:59:04 +0100 Subject: [PATCH] Hide traceback caused by KeyboardInterrupt. Use a decorator to not indent the whole function. --- apachedex/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apachedex/__init__.py b/apachedex/__init__.py index 74964ed..41897e6 100755 --- a/apachedex/__init__.py +++ b/apachedex/__init__.py @@ -1212,6 +1212,16 @@ def getTZInfo(tz): _tz_cache[tz] = tzi = AutoTZInfo(tz) return tzi +def _gracefulExit(*class_list): + @functools.wraps(func) + def wrapper(*args, **kw): + try: + return func(*args, **kw) + except KeyboardInterrupt: + sys.exit(1) + return wrapper + +@_gracefulExit def main(): parser = ShlexArgumentParser(description='Compute Apdex out of ' 'apache-style log files', fromfile_prefix_chars='@') -- 2.30.9