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

This commit is contained in:
Kris Maglione 2010-05-24 13:04:40 -04:00
parent 208db05798
commit 9adfeea6c2

View File

@ -1,4 +1,5 @@
import os import os
import signal
import subprocess import subprocess
import pygmi import pygmi
@ -10,10 +11,11 @@ def _():
def call(*args, **kwargs): def call(*args, **kwargs):
background = kwargs.pop('background', False) background = kwargs.pop('background', False)
pipe = subprocess.PIPE if not background else None
input = kwargs.pop('input', None) input = kwargs.pop('input', None)
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, p = subprocess.Popen(args, stdin=pipe, stdout=pipe, stderr=pipe,
stderr=subprocess.PIPE, cwd=os.environ['HOME'], preexec_fn=lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL),
close_fds=True, **kwargs) cwd=os.environ['HOME'], close_fds=True, **kwargs)
if not background: if not background:
return p.communicate(input)[0].rstrip('\n') return p.communicate(input)[0].rstrip('\n')