Changes: Fix python broken pipe randomly happened for Popen

RevBy: TrustMe
pull/1/head
Dmitry Rozenshtein 14 years ago
parent e7b24a3e76
commit 0d5962499f

1
debian/changelog vendored

@ -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 <alexey@trdhcp147241> Mon, 14 Nov 2011 13:39:38 +0200

@ -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)

@ -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 ...")

@ -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')

@ -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]

@ -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)

Loading…
Cancel
Save