Patchwork [2,of,5] pager: don't terminate with extreme prejudice on SIGPIPE (BC)

mail settings
Submitter Simon Farnsworth
Date Jan. 19, 2017, 7:02 p.m.
Message ID <>
Download mbox | patch
Permalink /patch/18262/
State Deferred
Headers show


Simon Farnsworth - Jan. 19, 2017, 7:02 p.m.
# HG changeset patch
# User Simon Farnsworth <>
# Date 1484836838 28800
#      Thu Jan 19 06:40:38 2017 -0800
# Node ID d444a9f4d468b7a0705d48b2f4f84c7bd44b6c74
# Parent  76123ae2e0ccaa58db3d4fc26b75b7251e13ad16
pager: don't terminate with extreme prejudice on SIGPIPE (BC)

The default SIGPIPE handler causes Mercurial to exit immediately, without
running any Python cleanup code (except and finally blocks, atexit handlers
etc). This creates problems if you want to do something at exit.

If we need a different exit code for broken pipe from pager, then we should
code that ourselves in Python; this appears to have been cargo-culted from
the fork implementation of pager that's no longer used, where it was needed
to stop Broken Pipe errors appearing on the user's terminal.


diff --git a/hgext/ b/hgext/
--- a/hgext/
+++ b/hgext/
@@ -92,7 +92,7 @@ 
     stderrfd = os.dup(util.stderr.fileno())
     os.dup2(pager.stdin.fileno(), util.stdout.fileno())
-    if ui._isatty(util.stderr):
+    if False and ui._isatty(util.stderr):
         os.dup2(pager.stdin.fileno(), util.stderr.fileno())
@@ -149,8 +149,6 @@ 
         if usepager:
             ui.setconfig('ui', 'formatted', ui.formatted(), 'pager')
             ui.setconfig('ui', 'interactive', False, 'pager')
-            if util.safehasattr(signal, "SIGPIPE"):
-                signal.signal(signal.SIGPIPE, signal.SIG_DFL)
         return orig(ui, options, cmd, cmdfunc)