本文整理汇总了Python中popen2._active方法的典型用法代码示例。如果您正苦于以下问题:Python popen2._active方法的具体用法?Python popen2._active怎么用?Python popen2._active使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类popen2
的用法示例。
在下文中一共展示了popen2._active方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: import popen2 [as 别名]
# 或者: from popen2 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]))
示例2: tearDown
# 需要导入模块: import popen2 [as 别名]
# 或者: from popen2 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()
示例3: _test
# 需要导入模块: import popen2 [as 别名]
# 或者: from popen2 import _active [as 别名]
def _test():
# same test as popen2._test(), but using the os.popen*() API
print "Testing os module:"
import popen2
# When the test runs, there shouldn't be any open pipes
popen2._cleanup()
assert not popen2._active, "Active pipes when test starts " + repr([c.cmd for c in popen2._active])
cmd = "cat"
teststr = "ab cd\n"
if os.name == "nt" or (is_jython and os._name == 'nt'):
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..."
w, r = os.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:
w, r, e = os.popen3([cmd])
except:
w, r, e = os.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 popen2._active[:]:
inst.wait()
popen2._cleanup()
if popen2._active:
raise ValueError("_active not empty")
print "All OK"