当前位置: 首页>>代码示例>>Python>>正文


Python tests.get_test_subprocess函数代码示例

本文整理汇总了Python中psutil.tests.get_test_subprocess函数的典型用法代码示例。如果您正苦于以下问题:Python get_test_subprocess函数的具体用法?Python get_test_subprocess怎么用?Python get_test_subprocess使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_test_subprocess函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_wait_procs_no_timeout

 def test_wait_procs_no_timeout(self):
     sproc1 = get_test_subprocess()
     sproc2 = get_test_subprocess()
     sproc3 = get_test_subprocess()
     procs = [psutil.Process(x.pid) for x in (sproc1, sproc2, sproc3)]
     for p in procs:
         p.terminate()
     gone, alive = psutil.wait_procs(procs)
开发者ID:mabuaita,项目名称:ops,代码行数:8,代码来源:test_system.py

示例2: setUp

 def setUp(self):
     env = os.environ.copy()
     env["THINK_OF_A_NUMBER"] = str(os.getpid())
     self.proc32 = get_test_subprocess([self.python32] + self.test_args,
                                       env=env,
                                       stdin=subprocess.PIPE)
     self.proc64 = get_test_subprocess([self.python64] + self.test_args,
                                       env=env,
                                       stdin=subprocess.PIPE)
开发者ID:4sp1r3,项目名称:psutil,代码行数:9,代码来源:test_windows.py

示例3: test_wait_procs

    def test_wait_procs(self):
        def callback(p):
            pids.append(p.pid)

        pids = []
        sproc1 = get_test_subprocess()
        sproc2 = get_test_subprocess()
        sproc3 = get_test_subprocess()
        procs = [psutil.Process(x.pid) for x in (sproc1, sproc2, sproc3)]
        self.assertRaises(ValueError, psutil.wait_procs, procs, timeout=-1)
        self.assertRaises(TypeError, psutil.wait_procs, procs, callback=1)
        t = time.time()
        gone, alive = psutil.wait_procs(procs, timeout=0.01, callback=callback)

        self.assertLess(time.time() - t, 0.5)
        self.assertEqual(gone, [])
        self.assertEqual(len(alive), 3)
        self.assertEqual(pids, [])
        for p in alive:
            self.assertFalse(hasattr(p, 'returncode'))

        @retry_before_failing(30)
        def test(procs, callback):
            gone, alive = psutil.wait_procs(procs, timeout=0.03,
                                            callback=callback)
            self.assertEqual(len(gone), 1)
            self.assertEqual(len(alive), 2)
            return gone, alive

        sproc3.terminate()
        gone, alive = test(procs, callback)
        self.assertIn(sproc3.pid, [x.pid for x in gone])
        if POSIX:
            self.assertEqual(gone.pop().returncode, -signal.SIGTERM)
        else:
            self.assertEqual(gone.pop().returncode, 1)
        self.assertEqual(pids, [sproc3.pid])
        for p in alive:
            self.assertFalse(hasattr(p, 'returncode'))

        @retry_before_failing(30)
        def test(procs, callback):
            gone, alive = psutil.wait_procs(procs, timeout=0.03,
                                            callback=callback)
            self.assertEqual(len(gone), 3)
            self.assertEqual(len(alive), 0)
            return gone, alive

        sproc1.terminate()
        sproc2.terminate()
        gone, alive = test(procs, callback)
        self.assertEqual(set(pids), set([sproc1.pid, sproc2.pid, sproc3.pid]))
        for p in gone:
            self.assertTrue(hasattr(p, 'returncode'))
开发者ID:mabuaita,项目名称:ops,代码行数:54,代码来源:test_system.py

示例4: subprocess_supports_unicode

def subprocess_supports_unicode(name):
    """Return True if both the fs and the subprocess module can
    deal with a unicode file name.
    """
    if PY3:
        return True
    try:
        safe_rmpath(name)
        create_exe(name)
        get_test_subprocess(cmd=[name])
    except UnicodeEncodeError:
        return False
    else:
        reap_children()
        return True
开发者ID:marcinkuzminski,项目名称:psutil,代码行数:15,代码来源:test_unicode.py

示例5: test_pids

    def test_pids(self):
        # Note: this test might fail if the OS is starting/killing
        # other processes in the meantime
        if SUNOS or AIX:
            cmd = ["ps", "-A", "-o", "pid"]
        else:
            cmd = ["ps", "ax", "-o", "pid"]
        p = get_test_subprocess(cmd, stdout=subprocess.PIPE)
        output = p.communicate()[0].strip()
        assert p.poll() == 0
        if PY3:
            output = str(output, sys.stdout.encoding)
        pids_ps = []
        for line in output.split('\n')[1:]:
            if line:
                pid = int(line.split()[0].strip())
                pids_ps.append(pid)
        # remove ps subprocess pid which is supposed to be dead in meantime
        pids_ps.remove(p.pid)
        pids_psutil = psutil.pids()
        pids_ps.sort()
        pids_psutil.sort()

        # on OSX and OPENBSD ps doesn't show pid 0
        if OSX or OPENBSD and 0 not in pids_ps:
            pids_ps.insert(0, 0)
        self.assertEqual(pids_ps, pids_psutil)
开发者ID:jomann09,项目名称:psutil,代码行数:27,代码来源:test_posix.py

示例6: test_proc_exe

 def test_proc_exe(self):
     subp = get_test_subprocess(cmd=[self.funky_name])
     p = psutil.Process(subp.pid)
     exe = p.exe()
     self.assertIsInstance(exe, str)
     if self.expect_exact_path_match():
         self.assertEqual(exe, self.funky_name)
开发者ID:giampaolo,项目名称:psutil,代码行数:7,代码来源:test_unicode.py

示例7: test_reap_children

 def test_reap_children(self):
     subp = get_test_subprocess()
     p = psutil.Process(subp.pid)
     assert p.is_running()
     reap_children()
     assert not p.is_running()
     assert not psutil.tests._pids_started
     assert not psutil.tests._subprocesses_started
开发者ID:jomann09,项目名称:psutil,代码行数:8,代码来源:test_misc.py

示例8: test_proc_cmdline

 def test_proc_cmdline(self):
     subp = get_test_subprocess(cmd=[self.funky_name])
     p = psutil.Process(subp.pid)
     cmdline = p.cmdline()
     for part in cmdline:
         self.assertIsInstance(part, str)
     if self.expect_exact_path_match():
         self.assertEqual(cmdline, [self.funky_name])
开发者ID:giampaolo,项目名称:psutil,代码行数:8,代码来源:test_unicode.py

示例9: test_pid_exists

 def test_pid_exists(self):
     sproc = get_test_subprocess()
     self.assertTrue(psutil.pid_exists(sproc.pid))
     p = psutil.Process(sproc.pid)
     p.kill()
     p.wait()
     self.assertFalse(psutil.pid_exists(sproc.pid))
     self.assertFalse(psutil.pid_exists(-1))
     self.assertEqual(psutil.pid_exists(0), 0 in psutil.pids())
开发者ID:mabuaita,项目名称:ops,代码行数:9,代码来源:test_system.py

示例10: test_ctrl_signals

 def test_ctrl_signals(self):
     p = psutil.Process(get_test_subprocess().pid)
     p.send_signal(signal.CTRL_C_EVENT)
     p.send_signal(signal.CTRL_BREAK_EVENT)
     p.kill()
     p.wait()
     self.assertRaises(psutil.NoSuchProcess,
                       p.send_signal, signal.CTRL_C_EVENT)
     self.assertRaises(psutil.NoSuchProcess,
                       p.send_signal, signal.CTRL_BREAK_EVENT)
开发者ID:4sp1r3,项目名称:psutil,代码行数:10,代码来源:test_windows.py

示例11: test_process_iter

    def test_process_iter(self):
        self.assertIn(os.getpid(), [x.pid for x in psutil.process_iter()])
        sproc = get_test_subprocess()
        self.assertIn(sproc.pid, [x.pid for x in psutil.process_iter()])
        p = psutil.Process(sproc.pid)
        p.kill()
        p.wait()
        self.assertNotIn(sproc.pid, [x.pid for x in psutil.process_iter()])

        with mock.patch("psutil.Process", side_effect=psutil.NoSuchProcess(os.getpid())):
            self.assertEqual(list(psutil.process_iter()), [])
        with mock.patch("psutil.Process", side_effect=psutil.AccessDenied(os.getpid())):
            with self.assertRaises(psutil.AccessDenied):
                list(psutil.process_iter())
开发者ID:DipoChiang,项目名称:DjangoCourse,代码行数:14,代码来源:test_system.py

示例12: test_proc_name

 def test_proc_name(self):
     subp = get_test_subprocess(cmd=[self.funky_name])
     if WINDOWS:
         # On Windows name() is determined from exe() first, because
         # it's faster; we want to overcome the internal optimization
         # and test name() instead of exe().
         with mock.patch("psutil._psplatform.cext.proc_exe",
                         side_effect=psutil.AccessDenied(os.getpid())) as m:
             name = psutil.Process(subp.pid).name()
             assert m.called
     else:
         name = psutil.Process(subp.pid).name()
     self.assertIsInstance(name, str)
     if self.expect_exact_path_match():
         self.assertEqual(name, os.path.basename(self.funky_name))
开发者ID:giampaolo,项目名称:psutil,代码行数:15,代码来源:test_unicode.py

示例13: test_proc_environ

 def test_proc_environ(self):
     # Note: differently from others, this test does not deal
     # with fs paths. On Python 2 subprocess module is broken as
     # it's not able to handle with non-ASCII env vars, so
     # we use "è", which is part of the extended ASCII table
     # (unicode point <= 255).
     env = os.environ.copy()
     funky_str = TESTFN_UNICODE if PY3 else 'è'
     env['FUNNY_ARG'] = funky_str
     sproc = get_test_subprocess(env=env)
     p = psutil.Process(sproc.pid)
     env = p.environ()
     for k, v in env.items():
         self.assertIsInstance(k, str)
         self.assertIsInstance(v, str)
     self.assertEqual(env['FUNNY_ARG'], funky_str)
开发者ID:marcinkuzminski,项目名称:psutil,代码行数:16,代码来源:test_unicode.py

示例14: test_environ

        # be executed.
        if SUNOS:
            kind = 'inet'
        try:
            self.execute('connections', kind=kind)
        finally:
            for s in socks:
                s.close()

    @unittest.skipUnless(hasattr(psutil.Process, 'environ'),
                         "Linux, OSX and Windows")
    def test_environ(self):
        self.execute("environ")


p = get_test_subprocess()
DEAD_PROC = psutil.Process(p.pid)
DEAD_PROC.kill()
DEAD_PROC.wait()
del p


class TestProcessObjectLeaksZombie(TestProcessObjectLeaks):
    """Same as above but looks for leaks occurring when dealing with
    zombie processes raising NoSuchProcess exception.
    """
    proc = DEAD_PROC

    def call(self, *args, **kwargs):
        try:
            TestProcessObjectLeaks.call(self, *args, **kwargs)
开发者ID:4sp1r3,项目名称:psutil,代码行数:31,代码来源:test_memory_leaks.py

示例15: setUpClass

 def setUpClass(cls):
     super(TestTerminatedProcessLeaks, cls).setUpClass()
     p = get_test_subprocess()
     cls.proc = psutil.Process(p.pid)
     cls.proc.kill()
     cls.proc.wait()
开发者ID:tijko,项目名称:psutil,代码行数:6,代码来源:test_memory_leaks.py


注:本文中的psutil.tests.get_test_subprocess函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。