From 0d5962499f4017f78bb86124679d0bb4c6145d90 Mon Sep 17 00:00:00 2001 From: Dmitry Rozenshtein Date: Fri, 2 Dec 2011 14:12:50 +0200 Subject: [PATCH] Changes: Fix python broken pipe randomly happened for Popen RevBy: TrustMe --- debian/changelog | 1 + .../testscripts/test-func-launcher.py | 2 +- tests/harmattan/testscripts/test-invoker.py | 4 ++-- tests/harmattan/testscripts/test-security.py | 2 +- .../testscripts/test-single-instance.py | 2 +- tests/harmattan/testscripts/utils.py | 20 ++++++++++++------- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/debian/changelog b/debian/changelog index 79c8686..d663c05 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,7 @@ applauncherd (3.0.1) unstable; urgency=low * Changes: Adds new test for applauncherd re-exec. Checking state of running application when it is updated. * Changes: single-instance library writes log messages to syslog instead of stderr * Changes: testcases added/fixed for code coverage + * Changes: Fix python broken pipe randomly happened for Popen -- Alexey Shilov Mon, 14 Nov 2011 13:39:38 +0200 diff --git a/tests/harmattan/testscripts/test-func-launcher.py b/tests/harmattan/testscripts/test-func-launcher.py index 62946fb..dce2304 100644 --- a/tests/harmattan/testscripts/test-func-launcher.py +++ b/tests/harmattan/testscripts/test-func-launcher.py @@ -634,7 +634,7 @@ class launcher_tests (unittest.TestCase): invoke="export QT_LOAD_TESTABILITY=1; /usr/bin/invoker --type=%s %s" %(btype, testapp) cmd.append(invoke) - p = subprocess.Popen(cmd, shell = False, stdout = DEV_NULL, stderr = DEV_NULL) + p = subprocess.Popen(cmd, shell = False, stdout = DEV_NULL, stderr = DEV_NULL, preexec_fn=permit_sigpipe) pid = wait_for_app(testapp) self.assert_(pid != None, "Can't start application %s" %testapp) diff --git a/tests/harmattan/testscripts/test-invoker.py b/tests/harmattan/testscripts/test-invoker.py index a8a7495..8c7c152 100644 --- a/tests/harmattan/testscripts/test-invoker.py +++ b/tests/harmattan/testscripts/test-invoker.py @@ -193,7 +193,7 @@ class InvokerTests(unittest.TestCase): p = Popen(['/usr/bin/invoker', '--delay', '10', '--type=m', '--no-wait', '/usr/bin/fala_ft_hello'], shell=False, - stdout=DEV_NULL, stderr=DEV_NULL) + stdout=DEV_NULL, stderr=DEV_NULL, preexec_fn=permit_sigpipe) # wait a little debug("waiting ...") @@ -527,7 +527,7 @@ class InvokerTests(unittest.TestCase): p = Popen(['/usr/bin/invoker', '--type=m', '--wait-term', '/usr/bin/fala_wait'], shell=False, - stdout=DEV_NULL, stderr=DEV_NULL) + stdout=DEV_NULL, stderr=DEV_NULL, preexec_fn=permit_sigpipe) # wait a little debug("waiting ...") diff --git a/tests/harmattan/testscripts/test-security.py b/tests/harmattan/testscripts/test-security.py index 9589a82..ac7b177 100644 --- a/tests/harmattan/testscripts/test-security.py +++ b/tests/harmattan/testscripts/test-security.py @@ -291,7 +291,7 @@ class SecurityTests(unittest.TestCase): """ handle = Popen(['/usr/bin/fala_ft_hello'], - stdout = DEV_NULL, stderr = DEV_NULL) + stdout = DEV_NULL, stderr = DEV_NULL, preexec_fn=permit_sigpipe) # give the application some time to launch up wait_for_app('fala_ft_hello') diff --git a/tests/harmattan/testscripts/test-single-instance.py b/tests/harmattan/testscripts/test-single-instance.py index 4c2dc96..c75dd87 100644 --- a/tests/harmattan/testscripts/test-single-instance.py +++ b/tests/harmattan/testscripts/test-single-instance.py @@ -161,7 +161,7 @@ class SingleInstanceTests(unittest.TestCase): def get_pid_full(self, app): p = subprocess.Popen(['pgrep', '-f', app], shell = False, - stdout = subprocess.PIPE, stderr = DEV_NULL) + stdout = subprocess.PIPE, stderr = DEV_NULL, preexec_fn=permit_sigpipe) op = p.communicate()[0] diff --git a/tests/harmattan/testscripts/utils.py b/tests/harmattan/testscripts/utils.py index 19cbe0d..5e53154 100644 --- a/tests/harmattan/testscripts/utils.py +++ b/tests/harmattan/testscripts/utils.py @@ -4,6 +4,7 @@ import commands import time import sys import re +import signal from subprocess import Popen from os.path import basename @@ -71,7 +72,7 @@ def start_applauncherd(): debug("Starting applauncherd") handle = Popen(['initctl', 'start', 'xsession/applauncherd'], stdout = DEV_NULL, stderr = DEV_NULL, - shell = False) + shell = False, preexec_fn=permit_sigpipe) get_booster_pid() return handle.wait() == 0 @@ -79,7 +80,7 @@ def stop_applauncherd(): debug("Stoping applauncherd") handle = Popen(['initctl', 'stop', 'xsession/applauncherd'], stdout = DEV_NULL, stderr = DEV_NULL, - shell = False) + shell = False, preexec_fn=permit_sigpipe) time.sleep(1) @@ -106,7 +107,7 @@ def run_app_as_user_with_invoker(appname, booster = 'm', arg = "", out = DEV_NUL else: raise TypeError("List or string expected") p = subprocess.Popen(cmd, shell = False, - stdout = out, stderr = err) + stdout = out, stderr = err, preexec_fn=permit_sigpipe) return p def run_cmd_as_user(cmnd, out = DEV_NULL, err = DEV_NULL): @@ -122,7 +123,7 @@ def run_cmd_as_user(cmnd, out = DEV_NULL, err = DEV_NULL): else: raise TypeError("List or string expected") p = subprocess.Popen(cmd, shell = False, - stdout = out, stderr = err) + stdout = out, stderr = err, preexec_fn=permit_sigpipe) return p def get_pid(appname, printdebug=True): @@ -146,7 +147,7 @@ def get_oldest_pid(appname): def get_newest_pid(app): p = subprocess.Popen(['pgrep', '-n', app], shell = False, - stdout = subprocess.PIPE, stderr = DEV_NULL) + stdout = subprocess.PIPE, stderr = DEV_NULL, preexec_fn=permit_sigpipe) op = p.communicate()[0] @@ -171,7 +172,7 @@ def wait_for_app(app = None, timeout = 40, sleep = 1): debug("Waiting for '%s' to startup in %ss time" %(app, timeout)) while pid == None and time.time() < start + timeout: p = subprocess.Popen(['pgrep', '-n', app], shell = False, - stdout = subprocess.PIPE, stderr = DEV_NULL) + stdout = subprocess.PIPE, stderr = DEV_NULL, preexec_fn=permit_sigpipe) op = p.communicate()[0] if p.wait() == 0: pid = op.strip() @@ -284,7 +285,7 @@ def get_creds(path = None, pid = None): return None handle = Popen(['/usr/bin/creds-get', '-p', str(pid)], - stdout = subprocess.PIPE) + stdout = subprocess.PIPE, preexec_fn=permit_sigpipe) op = handle.communicate()[0].strip() handle.wait() @@ -408,3 +409,8 @@ def isPackageInstalled(packageName): if(m and m.group(1).find("none")==-1): #m.group(1) contains version return True return False + +#trick to avoid broken pipe in Popen +#use ,preexec_fn=permit_sigpipe in each Popen +def permit_sigpipe(): + signal.signal(signal.SIGPIPE, signal.SIG_DFL)