Brodie Rao  committed 0958fbc

Disable preexec_fn/SIGPIPE usage on Windows (fixes #21)

  • Participants
  • Parent commits 19ca4a3

Comments (0)

Files changed (1)

     """Like the string-escape codec, but doesn't escape quotes"""
     return escapesub(lambda m: escapemap[], s[:-1]) + ' (esc)\n'
-def resetsigpipe():
-    """Reset SIGPIPE to SIG_DFL (for use in subprocesses).
+def makeresetsigpipe():
+    """Make a function to reset SIGPIPE to SIG_DFL (for use in subprocesses).
-    Doing subprocess.Popen(..., preexec_fn=resetsigpipe) will prevent
+    Doing subprocess.Popen(..., preexec_fn=makeresetsigpipe()) will prevent
     Python's SIGPIPE handler (SIG_IGN) from being inherited by the
     child process.
-    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
+    if sys.platform == 'win32' or getattr(signal, 'SIGPIPE', None) is None:
+        return None
+    return lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL)
 def test(path, indent=2, shell='/bin/sh'):
     """Run test at path and return input, output, and diff.
     p = subprocess.Popen([shell, '-'], bufsize=-1, stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                          universal_newlines=True, env=env,
-                         preexec_fn=resetsigpipe,
+                         preexec_fn=makeresetsigpipe(),
                 == 'posix')
     salt = 'CRAM%s' % time.time()