def test_start_child(self, run, fork): fork.return_value = 0 p = Process(Mock()) # test p.start() # validation fork.assert_called_once_with() run.assert_called_once_with()
def test_start_parent(self, run, fork): fork.return_value = 1234 p = Process(Mock()) # test p.start() # validation fork.assert_called_once_with() self.assertFalse(run.called) self.assertEqual(p.pid, fork.return_value)
def __call__(self): """ Invoke the RMI as follows: - Fork - Start the monitor. - Read and dispatch reply messages. :return: Whatever method returned. """ pipe = Pipe() target = Target(self.method, *self.args, **self.kwargs) child = Process(target, pipe) monitor = Monitor(Context.current(), child) try: child.start() monitor.start() pipe.writer.close() retval = self.read(pipe.reader) return retval finally: pipe.close() monitor.stop() child.wait()