Commit bdefe5dd authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Support arguments in utils.RunInSeparateProcess

Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarGuido Trotter <>
parent 44caf5a8
......@@ -2156,15 +2156,15 @@ def GetFilesystemStats(path):
return (tsize, fsize)
def RunInSeparateProcess(fn):
def RunInSeparateProcess(fn, *args):
"""Runs a function in a separate process.
Note: Only boolean return values are supported.
@type fn: callable
@param fn: Function to be called
@rtype: tuple of (int/None, int/None)
@return: Exit code and signal number
@rtype: bool
@return: Function's result
pid = os.fork()
......@@ -2175,7 +2175,7 @@ def RunInSeparateProcess(fn):
# Call function
result = int(bool(fn()))
result = int(bool(fn(*args)))
assert result in (0, 1)
except: # pylint: disable-msg=W0702
logging.exception("Error while calling function in separate process")
......@@ -1200,6 +1200,13 @@ class RunInSeparateProcess(unittest.TestCase):
self.assertEqual(exp, utils.RunInSeparateProcess(_child))
def testArgs(self):
for arg in [0, 1, 999, "Hello World", (1, 2, 3)]:
def _child(carg1, carg2):
return carg1 == "Foo" and carg2 == arg
self.assert_(utils.RunInSeparateProcess(_child, "Foo", arg))
def testPid(self):
parent_pid = os.getpid()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment