diff --git a/ubuntutools/subprocess.py b/ubuntutools/subprocess.py index 688d607..2fc4b37 100644 --- a/ubuntutools/subprocess.py +++ b/ubuntutools/subprocess.py @@ -21,24 +21,25 @@ from subprocess import PIPE, STDOUT, CalledProcessError __all__ = ['Popen', 'call', 'check_call', 'check_output', 'CalledProcessError', 'PIPE', 'STDOUT'] -def Popen(*args, **kwargs): - kwargs.setdefault('close_fds', True) +class Popen(subprocess.Popen): + def __init__(self, *args, **kwargs): + kwargs.setdefault('close_fds', True) - if 'restore_signals' not in inspect.getargspec(subprocess.Popen.__init__)[0]: - given_preexec_fn = kwargs.pop('preexec_fn', None) - restore_signals = kwargs.pop('restore_signals', True) - def preexec_fn(): - if restore_signals: - for sig in ('SIGPIPE', 'SIGXFZ', 'SIGXFSZ'): - if hasattr(signal, sig): - signal.signal(getattr(signal, sig), - signal.SIG_DFL) + if 'restore_signals' not in inspect.getargspec(subprocess.Popen.__init__)[0]: + given_preexec_fn = kwargs.pop('preexec_fn', None) + restore_signals = kwargs.pop('restore_signals', True) + def preexec_fn(): + if restore_signals: + for sig in ('SIGPIPE', 'SIGXFZ', 'SIGXFSZ'): + if hasattr(signal, sig): + signal.signal(getattr(signal, sig), + signal.SIG_DFL) - if given_preexec_fn: - given_preexec_fn() - kwargs['preexec_fn'] = preexec_fn + if given_preexec_fn: + given_preexec_fn() + kwargs['preexec_fn'] = preexec_fn - return subprocess.Popen(*args, **kwargs) + subprocess.Popen.__init__(self, *args, **kwargs) # call, check_call, and check_output are copied directly from the diff --git a/ubuntutools/test/test_pylint.py b/ubuntutools/test/test_pylint.py index 8a1c650..7806abf 100644 --- a/ubuntutools/test/test_pylint.py +++ b/ubuntutools/test/test_pylint.py @@ -28,8 +28,8 @@ WHITELIST = [re.compile(': %s$' % x) for x in ( # mox: r"Instance of '.+' has no '(WithSideEffects|MultipleTimes|AndReturn)' " r"member", - # Wrong Popen - r"Function 'Popen' has no '__init__' member", + # pylint doesn't like *args/**kwargs + r"Instance of 'Popen' has no '.*' member", )] class PylintTestCase(unittest.TestCase):