當前位置: 首頁>>代碼示例>>Python>>正文


Python subprocess._active方法代碼示例

本文整理匯總了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]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_subprocess.py

示例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() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_subprocess.py

示例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]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:33,代碼來源:test_subprocess.py

示例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])) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_popen2.py

示例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() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:test_popen2.py

示例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") 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:7,代碼來源:test_subprocess.py

示例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]) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:33,代碼來源:test_subprocess.py

示例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" 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:40,代碼來源:popen2.py


注:本文中的subprocess._active方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。