本文整理汇总了Python中subprocess._active方法的典型用法代码示例。如果您正苦于以下问题:Python subprocess._active方法的具体用法?Python subprocess._active怎么用?Python subprocess._active使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess
的用法示例。
在下文中一共展示了subprocess._active方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_zombie_fast_process_del
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import _active [as 别名]
def test_zombie_fast_process_del(self):
# Issue #12650: on Unix, if Popen.__del__() was called before the
# process exited, it wouldn't be added to subprocess._active, and would
# remain a zombie.
# spawn a Popen, and delete its reference before it exits
p = subprocess.Popen([sys.executable, "-c",
'import sys, time;'
'time.sleep(0.2)'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.addCleanup(p.stdout.close)
self.addCleanup(p.stderr.close)
ident = id(p)
pid = p.pid
del p
# check that p is in the active processes list
self.assertIn(ident, [id(o) for o in subprocess._active])
示例2: tearDown
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import _active [as 别名]
def tearDown(self):
for inst in subprocess._active:
inst.wait()
subprocess._cleanup()
self.assertFalse(subprocess._active, "subprocess._active not empty")
self.doCleanups()
test_support.reap_children()
示例3: test_leak_fast_process_del_killed
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import _active [as 别名]
def test_leak_fast_process_del_killed(self):
# Issue #12650: on Unix, if Popen.__del__() was called before the
# process exited, and the process got killed by a signal, it would never
# be removed from subprocess._active, which triggered a FD and memory
# leak.
# spawn a Popen, delete its reference and kill it
p = subprocess.Popen([sys.executable, "-c",
'import time;'
'time.sleep(3)'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.addCleanup(p.stdout.close)
self.addCleanup(p.stderr.close)
ident = id(p)
pid = p.pid
del p
os.kill(pid, signal.SIGKILL)
# check that p is in the active processes list
self.assertIn(ident, [id(o) for o in subprocess._active])
# let some time for the process to exit, and create a new Popen: this
# should trigger the wait() of p
time.sleep(0.2)
with self.assertRaises(EnvironmentError) as c:
with subprocess.Popen(['nonexisting_i_hope'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE) as proc:
pass
# p should have been wait()ed on, and removed from the _active list
self.assertRaises(OSError, os.waitpid, pid, 0)
self.assertNotIn(ident, [id(o) for o in subprocess._active])
示例4: setUp
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import _active [as 别名]
def setUp(self):
popen2._cleanup()
# When the test runs, there shouldn't be any open pipes
self.assertFalse(popen2._active, "Active pipes when test starts" +
repr([c.cmd for c in popen2._active]))
示例5: tearDown
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import _active [as 别名]
def tearDown(self):
for inst in popen2._active:
inst.wait()
popen2._cleanup()
self.assertFalse(popen2._active, "popen2._active not empty")
# The os.popen*() API delegates to the subprocess module (on Unix)
import subprocess
for inst in subprocess._active:
inst.wait()
subprocess._cleanup()
self.assertFalse(subprocess._active, "subprocess._active not empty")
reap_children()
示例6: tearDown
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import _active [as 别名]
def tearDown(self):
for inst in subprocess._active:
inst.wait()
subprocess._cleanup()
self.assertFalse(subprocess._active, "subprocess._active not empty")
示例7: test_leak_fast_process_del_killed
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import _active [as 别名]
def test_leak_fast_process_del_killed(self):
# Issue #12650: on Unix, if Popen.__del__() was called before the
# process exited, and the process got killed by a signal, it would never
# be removed from subprocess._active, which triggered a FD and memory
# leak.
# spawn a Popen, delete its reference and kill it
p = subprocess.Popen([sys.executable, "-c",
'import time;'
'time.sleep(3)'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.addCleanup(p.stdout.close)
self.addCleanup(p.stderr.close)
ident = id(p)
pid = p.pid
del p
os.kill(pid, signal.SIGKILL)
# check that p is in the active processes list
self.assertIn(ident, [id(o) for o in subprocess._active])
# let some time for the process to exit, and create a new Popen: this
# should trigger the wait() of p
time.sleep(0.2)
with self.assertRaises(OSError) as c:
with subprocess.Popen(['nonexisting_i_hope'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE) as proc:
pass
# p should have been wait()ed on, and removed from the _active list
self.assertRaises(OSError, os.waitpid, pid, 0)
self.assertNotIn(ident, [id(o) for o in subprocess._active])
示例8: _test
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import _active [as 别名]
def _test():
# When the test runs, there shouldn't be any open pipes
_cleanup()
assert not _active, "Active pipes when test starts " + repr([c.cmd for c in _active])
cmd = "cat"
teststr = "ab cd\n"
if os.name in ("nt", "java"):
cmd = "more"
# "more" doesn't act the same way across Windows flavors,
# sometimes adding an extra newline at the start or the
# end. So we strip whitespace off both ends for comparison.
expected = teststr.strip()
print "testing popen2..."
r, w = popen2(cmd)
w.write(teststr)
w.close()
got = r.read()
if got.strip() != expected:
raise ValueError("wrote %r read %r" % (teststr, got))
print "testing popen3..."
try:
r, w, e = popen3([cmd])
except:
r, w, e = popen3(cmd)
w.write(teststr)
w.close()
got = r.read()
if got.strip() != expected:
raise ValueError("wrote %r read %r" % (teststr, got))
got = e.read()
if got:
raise ValueError("unexpected %r on stderr" % (got,))
for inst in _active[:]:
inst.wait()
_cleanup()
if _active:
raise ValueError("_active not empty")
print "All OK"