示例#1
0
def subprocess_supports_unicode(suffix):
    """Return True if both the fs and the subprocess module can
    deal with a unicode file name.
    """
    if PY3:
        return True
    name = get_testfn(suffix=suffix)
    sproc = None
    try:
        safe_rmpath(name)
        create_exe(name)
        sproc = get_test_subprocess(cmd=[name])
    except UnicodeEncodeError:
        return False
    else:
        return True
    finally:
        if sproc is not None:
            terminate(sproc)
示例#2
0
    def test_spawn_children_pair(self):
        child, grandchild = self.spawn_children_pair()
        self.assertNotEqual(child.pid, grandchild.pid)
        assert child.is_running()
        assert grandchild.is_running()
        children = psutil.Process().children()
        self.assertEqual(children, [child])
        children = psutil.Process().children(recursive=True)
        self.assertEqual(len(children), 2)
        self.assertIn(child, children)
        self.assertIn(grandchild, children)
        self.assertEqual(child.ppid(), os.getpid())
        self.assertEqual(grandchild.ppid(), child.pid)

        terminate(child)
        assert not child.is_running()
        assert grandchild.is_running()

        terminate(grandchild)
        assert not grandchild.is_running()
def try_unicode(suffix):
    """Return True if both the fs and the subprocess module can
    deal with a unicode file name.
    """
    sproc = None
    testfn = get_testfn(suffix=suffix)
    try:
        safe_rmpath(testfn)
        create_exe(testfn)
        sproc = spawn_testproc(cmd=[testfn])
        shutil.copyfile(testfn, testfn + '-2')
        safe_rmpath(testfn + '-2')
    except (UnicodeEncodeError, IOError):
        return False
    else:
        return True
    finally:
        if sproc is not None:
            terminate(sproc)
        safe_rmpath(testfn)
示例#4
0
 def test_terminate(self):
     # by subprocess.Popen
     p = self.spawn_testproc()
     terminate(p)
     self.assertProcessGone(p)
     terminate(p)
     # by psutil.Process
     p = psutil.Process(self.spawn_testproc().pid)
     terminate(p)
     self.assertProcessGone(p)
     terminate(p)
     # by psutil.Popen
     cmd = [PYTHON_EXE, "-c", "import time; time.sleep(60);"]
     p = psutil.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     terminate(p)
     self.assertProcessGone(p)
     terminate(p)
     # by PID
     pid = self.spawn_testproc().pid
     terminate(pid)
     self.assertProcessGone(p)
     terminate(pid)
     # zombie
     if POSIX:
         parent, zombie = self.spawn_zombie()
         terminate(parent)
         terminate(zombie)
         self.assertProcessGone(parent)
         self.assertProcessGone(zombie)
示例#5
0
 def tearDownClass(cls):
     terminate(cls.pid)
示例#6
0
 def test_terminate(self):
     # by subprocess.Popen
     p = self.get_test_subprocess()
     terminate(p)
     assert not psutil.pid_exists(p.pid)
     terminate(p)
     # by psutil.Process
     p = psutil.Process(self.get_test_subprocess().pid)
     terminate(p)
     assert not psutil.pid_exists(p.pid)
     terminate(p)
     # by psutil.Popen
     cmd = [PYTHON_EXE, "-c", "import time; time.sleep(60);"]
     p = psutil.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     terminate(p)
     assert not psutil.pid_exists(p.pid)
     terminate(p)
     # by PID
     pid = self.get_test_subprocess().pid
     terminate(pid)
     assert not psutil.pid_exists(pid)
     terminate(pid)
     # zombie
     parent, zombie = self.create_zombie_proc()
     terminate(parent)
     terminate(zombie)
     assert not psutil.pid_exists(parent.pid)
     assert not psutil.pid_exists(zombie.pid)
示例#7
0
 def tearDownClass(cls):
     terminate(cls.zombie)
     terminate(cls.parent)  # executed first
示例#8
0
 def tearDownClass(cls):
     terminate(cls.parent)
     terminate(cls.zombie)
示例#9
0
 def tearDownClass(cls):
     super().tearDownClass()
     terminate(cls.subp)