def test_execute_command_with_pid(self):
        pid_file = os.path.join(tempfile.gettempdir(), 'mog-commons-python-test.pid')

        class RunSleep(threading.Thread):
            def run(self):
                execute_command_with_pid('python -c "import time;time.sleep(2)"', pid_file, shell=True)

        th = RunSleep()
        th.start()
        time.sleep(1)

        with open(pid_file, 'r') as f:
            pid = int(f.read())

        self.assertTrue(pid_exists(pid))
        time.sleep(2)
        self.assertFalse(pid_exists(pid))

        self.assertEqual(execute_command_with_pid(['exit', '2'], None, shell=True), 2)