From patchwork Mon Jul 13 12:40:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2,of,2] dispatch: handle late KeyboardInterrupt occurred in run() From: Yuya Nishihara X-Patchwork-Id: 46718 Message-Id: <96904994ee794243dd57.1594644046@mimosa> To: mercurial-devel@mercurial-scm.org Date: Mon, 13 Jul 2020 21:40:46 +0900 # HG changeset patch # User Yuya Nishihara # Date 1594642460 -32400 # Mon Jul 13 21:14:20 2020 +0900 # Node ID 96904994ee794243dd57881e5eb24540d7c2aaf2 # Parent 39c2578fd3da0e2d526b9a4107e25c833e6be050 dispatch: handle late KeyboardInterrupt occurred in run() User can press Ctrl+C while flushing streams in dispatch.run(). In such case, I think exiting with 255 is better than printing Python traceback and exiting with 1. diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -140,8 +140,10 @@ def run(): status = -1 _silencestdio() - finally: - pass + except KeyboardInterrupt: + # Catch early/late KeyboardInterrupt as last ditch. Here nothing will + # be printed to console to avoid another IOError/KeyboardInterrupt. + status = -1 sys.exit(status & 255)