From bdefe5dd311f72b591a4dcf50e01715930d2f00d Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Fri, 26 Feb 2010 18:39:49 +0100 Subject: [PATCH] Support arguments in utils.RunInSeparateProcess Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- lib/utils.py | 8 ++++---- test/ganeti.utils_unittest.py | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/utils.py b/lib/utils.py index 131f4c1a7..53f5eb234 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -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): ResetTempfileModule() # 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") diff --git a/test/ganeti.utils_unittest.py b/test/ganeti.utils_unittest.py index 8392ad056..14954684a 100755 --- a/test/ganeti.utils_unittest.py +++ b/test/ganeti.utils_unittest.py @@ -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() -- GitLab