Revision bdefe5dd

b/lib/utils.py
2156 2156
  return (tsize, fsize)
2157 2157

  
2158 2158

  
2159
def RunInSeparateProcess(fn):
2159
def RunInSeparateProcess(fn, *args):
2160 2160
  """Runs a function in a separate process.
2161 2161

  
2162 2162
  Note: Only boolean return values are supported.
2163 2163

  
2164 2164
  @type fn: callable
2165 2165
  @param fn: Function to be called
2166
  @rtype: tuple of (int/None, int/None)
2167
  @return: Exit code and signal number
2166
  @rtype: bool
2167
  @return: Function's result
2168 2168

  
2169 2169
  """
2170 2170
  pid = os.fork()
......
2175 2175
      ResetTempfileModule()
2176 2176

  
2177 2177
      # Call function
2178
      result = int(bool(fn()))
2178
      result = int(bool(fn(*args)))
2179 2179
      assert result in (0, 1)
2180 2180
    except: # pylint: disable-msg=W0702
2181 2181
      logging.exception("Error while calling function in separate process")
b/test/ganeti.utils_unittest.py
1200 1200

  
1201 1201
      self.assertEqual(exp, utils.RunInSeparateProcess(_child))
1202 1202

  
1203
  def testArgs(self):
1204
    for arg in [0, 1, 999, "Hello World", (1, 2, 3)]:
1205
      def _child(carg1, carg2):
1206
        return carg1 == "Foo" and carg2 == arg
1207

  
1208
      self.assert_(utils.RunInSeparateProcess(_child, "Foo", arg))
1209

  
1203 1210
  def testPid(self):
1204 1211
    parent_pid = os.getpid()
1205 1212

  

Also available in: Unified diff