[hackers] [wmii] [pygmi] Don't launch background processes with IO pipes. Restore SIGPIPE. (Closes issue #176) || Kris Maglione

From: <hg_AT_suckless.org>
Date: Mon, 24 May 2010 17:04:53 +0000 (UTC)

changeset: 2635:3d03873142c0
tag: tip
user: Kris Maglione <kris_AT_suckless.org>
date: Mon May 24 13:04:40 2010 -0400
files: alternative_wmiircs/python/pygmi/util.py
description:
[pygmi] Don't launch background processes with IO pipes. Restore SIGPIPE. (Closes issue #176)

diff -r 8c7a4ce5da9c -r 3d03873142c0 alternative_wmiircs/python/pygmi/util.py
--- a/alternative_wmiircs/python/pygmi/util.py Mon May 24 13:01:48 2010 -0400
+++ b/alternative_wmiircs/python/pygmi/util.py Mon May 24 13:04:40 2010 -0400
@@ -1,4 +1,5 @@
 import os
+import signal
 import subprocess
 
 import pygmi
@@ -10,10 +11,11 @@
 
 def call(*args, **kwargs):
     background = kwargs.pop('background', False)
+ pipe = subprocess.PIPE if not background else None
     input = kwargs.pop('input', None)
- p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, cwd=os.environ['HOME'],
- close_fds=True, **kwargs)
+ p = subprocess.Popen(args, stdin=pipe, stdout=pipe, stderr=pipe,
+ preexec_fn=lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL),
+ cwd=os.environ['HOME'], close_fds=True, **kwargs)
     if not background:
         return p.communicate(input)[0].rstrip('\n')
 
Received on Mon May 24 2010 - 17:04:53 UTC

This archive was generated by hypermail 2.2.0 : Mon May 24 2010 - 17:12:04 UTC