本文整理汇总了Python中test_psutil.get_test_subprocess函数的典型用法代码示例。如果您正苦于以下问题:Python get_test_subprocess函数的具体用法?Python get_test_subprocess怎么用?Python get_test_subprocess使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_test_subprocess函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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)
示例2: test_pids
def test_pids(self):
# Note: this test might fail if the OS is starting/killing
# other processes in the meantime
if SUNOS:
cmd = ["ps", "ax"]
else:
cmd = ["ps", "ax", "-o", "pid"]
p = get_test_subprocess(cmd, stdout=subprocess.PIPE)
output = p.communicate()[0].strip()
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 ps doesn't show pid 0
if OSX and 0 not in pids_ps:
pids_ps.insert(0, 0)
if pids_ps != pids_psutil:
difference = [x for x in pids_psutil if x not in pids_ps] + \
[x for x in pids_ps if x not in pids_psutil]
self.fail("difference: " + str(difference))
示例3: test_get_pids
def test_get_pids(self):
# Note: this test might fail if the OS is starting/killing
# other processes in the meantime
p = get_test_subprocess(["ps", "ax", "-o", "pid"], stdout=subprocess.PIPE)
output = p.communicate()[0].strip()
if PY3:
output = str(output, sys.stdout.encoding)
output = output.replace("PID", "")
p.wait()
pids_ps = []
for pid in output.split("\n"):
if pid:
pids_ps.append(int(pid.strip()))
# remove ps subprocess pid which is supposed to be dead in meantime
pids_ps.remove(p.pid)
pids_psutil = psutil.get_pid_list()
pids_ps.sort()
pids_psutil.sort()
# on OSX ps doesn't show pid 0
if OSX and 0 not in pids_ps:
pids_ps.insert(0, 0)
if pids_ps != pids_psutil:
difference = [x for x in pids_psutil if x not in pids_ps] + [x for x in pids_ps if x not in pids_psutil]
self.fail("difference: " + str(difference))
示例4: 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)
示例5: test_memory_maps
def test_memory_maps(self):
sproc = get_test_subprocess()
time.sleep(1)
p = psutil.Process(sproc.pid)
maps = p.get_memory_maps(grouped=False)
pmap = sh('pmap -x %s' % p.pid).split('\n')
del pmap[0]; del pmap[0] # get rid of header
while maps and pmap:
this = maps.pop(0)
other = pmap.pop(0)
addr, _, rss, dirty, mode, path = other.split(None, 5)
if not path.startswith('[') and not path.endswith(']'):
self.assertEqual(path, os.path.basename(this.path))
self.assertEqual(int(rss) * 1024, this.rss)
# test only rwx chars, ignore 's' and 'p'
self.assertEqual(mode[:3], this.perms[:3])
示例6: setUp
def setUp(self):
sproc = get_test_subprocess()
wait_for_pid(sproc.pid)
self.pid = sproc.pid
示例7: setUpClass
def setUpClass(cls):
cls.pid = get_test_subprocess([PYTHON, "-E", "-O"],
stdin=subprocess.PIPE).pid
wait_for_pid(cls.pid)
示例8: setUpClass
def setUpClass(cls):
cls.pid = get_test_subprocess().pid
示例9: test_proc_cmdline
def test_proc_cmdline(self):
shutil.copyfile(sys.executable, self.uexe)
subp = get_test_subprocess(cmd=[self.uexe])
p = psutil.Process(subp.pid)
self.assertIsInstance("".join(p.cmdline()), str)
self.assertEqual(p.cmdline(), [self.uexe])
示例10: test_proc_name
def test_proc_name(self):
from psutil._pswindows import py2_strencode
shutil.copyfile(sys.executable, self.uexe)
subp = get_test_subprocess(cmd=[self.uexe])
self.assertEqual(py2_strencode(psutil._psplatform.cext.proc_name(subp.pid)), "psutil-è.exe")
示例11: test_proc_exe
def test_proc_exe(self):
shutil.copyfile(sys.executable, self.uexe)
subp = get_test_subprocess(cmd=[self.uexe])
p = psutil.Process(subp.pid)
self.assertIsInstance(p.name(), str)
self.assertEqual(os.path.basename(p.name()), "psutil-è.exe")
示例12: get_test_subprocess
s.listen(1)
socks.append(s)
kind = 'all'
# TODO: UNIX sockets are temporarily implemented by parsing
# 'pfiles' cmd output; we don't want that part of the code to
# be executed.
if SUNOS:
kind = 'inet'
try:
self.execute('connections', kind=kind)
finally:
for s in socks:
s.close()
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)
示例13: setUp
def setUp(self):
self.pid = get_test_subprocess([PYTHON, "-E", "-O"], stdin=subprocess.PIPE).pid
示例14: setUp
def setUp(self):
self.pid = get_test_subprocess().pid
示例15: setUp
def setUp(self):
self.proc32 = get_test_subprocess([self.python32] + self.test_args)
self.proc64 = get_test_subprocess([self.python64] + self.test_args)