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() def _check(): return os.getpid() == parent_pid self.failIf(utils.RunInSeparateProcess(_check))
def test(self): for exp in [True, False]: def _child(): return exp self.assertEqual(exp, utils.RunInSeparateProcess(_child))
def testLockHeldByOtherProcess(self): lockfile = utils.PathJoin(self.tmpdir, "lock") lock = utils.FileLock.Open(lockfile) lock.Exclusive(blocking=True, timeout=1.0) try: self.assertTrue(utils.RunInSeparateProcess(self._TryLock, lockfile)) finally: lock.Close()
def test(self): (pid_read_fd, pid_write_fd) = os.pipe() # Start short-lived process which writes its PID to pipe self.assert_(utils.RunInSeparateProcess(self._WritePid, pid_write_fd)) os.close(pid_write_fd) # Read PID from pipe pid = int(os.read(pid_read_fd, 1024)) os.close(pid_read_fd) # Try to send signal to process which exited recently self.assertFalse(utils.IgnoreProcessNotFound(os.kill, pid, 0))
def testRealProcess(self): self.assert_(utils.RunInSeparateProcess(self._TestRealProcess))
def _TryLock(self, *args): return utils.RunInSeparateProcess(self._TryLockInner, self.tmpfile.name, *args)
def _Test(self, *args): # Need to use separate process as we want to change TZ self.assertTrue(utils.RunInSeparateProcess(self._TestInProcess, *args))
if not options.yes_do_it: sys.stdout.write("The 'no voting' option has been selected.\n") sys.stdout.write("This is dangerous, please confirm by" " typing uppercase 'yes': ") sys.stdout.flush() confirmation = sys.stdin.readline().strip() if confirmation != "YES": print >> sys.stderr, "Aborting." sys.exit(constants.EXIT_FAILURE) else: # CheckAgreement uses RPC and threads, hence it needs to be run in # a separate process before we call utils.Daemonize in the current # process. if not utils.RunInSeparateProcess(CheckAgreement): sys.exit(constants.EXIT_FAILURE) # ActivateMasterIP also uses RPC/threads, so we run it again via a # separate process. # TODO: decide whether failure to activate the master IP is a fatal error utils.RunInSeparateProcess(ActivateMasterIP) def PrepMasterd(options, _): """Prep master daemon function, executed with the PID file held. """ # This is safe to do as the pid file guarantees against # concurrent execution.