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


Python Subprocess.STREAM屬性代碼示例

本文整理匯總了Python中tornado.process.Subprocess.STREAM屬性的典型用法代碼示例。如果您正苦於以下問題:Python Subprocess.STREAM屬性的具體用法?Python Subprocess.STREAM怎麽用?Python Subprocess.STREAM使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在tornado.process.Subprocess的用法示例。


在下文中一共展示了Subprocess.STREAM屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_subprocess

# 需要導入模塊: from tornado.process import Subprocess [as 別名]
# 或者: from tornado.process.Subprocess import STREAM [as 別名]
def test_subprocess(self):
        subproc = Subprocess([sys.executable, '-u', '-i'],
                             stdin=Subprocess.STREAM,
                             stdout=Subprocess.STREAM, stderr=subprocess.STDOUT,
                             io_loop=self.io_loop)
        self.addCleanup(lambda: os.kill(subproc.pid, signal.SIGTERM))
        subproc.stdout.read_until(b'>>> ', self.stop)
        self.wait()
        subproc.stdin.write(b"print('hello')\n")
        subproc.stdout.read_until(b'\n', self.stop)
        data = self.wait()
        self.assertEqual(data, b"hello\n")

        subproc.stdout.read_until(b">>> ", self.stop)
        self.wait()
        subproc.stdin.write(b"raise SystemExit\n")
        subproc.stdout.read_until_close(self.stop)
        data = self.wait()
        self.assertEqual(data, b"") 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:21,代碼來源:process_test.py

示例2: test_subprocess

# 需要導入模塊: from tornado.process import Subprocess [as 別名]
# 或者: from tornado.process.Subprocess import STREAM [as 別名]
def test_subprocess(self):
        if IOLoop.configured_class().__name__.endswith('LayeredTwistedIOLoop'):
            # This test fails non-deterministically with LayeredTwistedIOLoop.
            # (the read_until('\n') returns '\n' instead of 'hello\n')
            # This probably indicates a problem with either TornadoReactor
            # or TwistedIOLoop, but I haven't been able to track it down
            # and for now this is just causing spurious travis-ci failures.
            raise unittest.SkipTest("Subprocess tests not compatible with "
                                    "LayeredTwistedIOLoop")
        subproc = Subprocess([sys.executable, '-u', '-i'],
                             stdin=Subprocess.STREAM,
                             stdout=Subprocess.STREAM, stderr=subprocess.STDOUT)
        self.addCleanup(lambda: (subproc.proc.terminate(), subproc.proc.wait()))
        self.addCleanup(subproc.stdout.close)
        self.addCleanup(subproc.stdin.close)
        yield subproc.stdout.read_until(b'>>> ')
        subproc.stdin.write(b"print('hello')\n")
        data = yield subproc.stdout.read_until(b'\n')
        self.assertEqual(data, b"hello\n")

        yield subproc.stdout.read_until(b">>> ")
        subproc.stdin.write(b"raise SystemExit\n")
        data = yield subproc.stdout.read_until_close()
        self.assertEqual(data, b"") 
開發者ID:tp4a,項目名稱:teleport,代碼行數:26,代碼來源:process_test.py

示例3: test_subprocess

# 需要導入模塊: from tornado.process import Subprocess [as 別名]
# 或者: from tornado.process.Subprocess import STREAM [as 別名]
def test_subprocess(self):
        if IOLoop.configured_class().__name__.endswith('LayeredTwistedIOLoop'):
            # This test fails non-deterministically with LayeredTwistedIOLoop.
            # (the read_until('\n') returns '\n' instead of 'hello\n')
            # This probably indicates a problem with either TornadoReactor
            # or TwistedIOLoop, but I haven't been able to track it down
            # and for now this is just causing spurious travis-ci failures.
            raise unittest.SkipTest("Subprocess tests not compatible with "
                                    "LayeredTwistedIOLoop")
        subproc = Subprocess([sys.executable, '-u', '-i'],
                             stdin=Subprocess.STREAM,
                             stdout=Subprocess.STREAM, stderr=subprocess.STDOUT,
                             io_loop=self.io_loop)
        self.addCleanup(lambda: os.kill(subproc.pid, signal.SIGTERM))
        subproc.stdout.read_until(b'>>> ', self.stop)
        self.wait()
        subproc.stdin.write(b"print('hello')\n")
        subproc.stdout.read_until(b'\n', self.stop)
        data = self.wait()
        self.assertEqual(data, b"hello\n")

        subproc.stdout.read_until(b">>> ", self.stop)
        self.wait()
        subproc.stdin.write(b"raise SystemExit\n")
        subproc.stdout.read_until_close(self.stop)
        data = self.wait()
        self.assertEqual(data, b"") 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:29,代碼來源:process_test.py

示例4: test_close_stdin

# 需要導入模塊: from tornado.process import Subprocess [as 別名]
# 或者: from tornado.process.Subprocess import STREAM [as 別名]
def test_close_stdin(self):
        # Close the parent's stdin handle and see that the child recognizes it.
        subproc = Subprocess([sys.executable, '-u', '-i'],
                             stdin=Subprocess.STREAM,
                             stdout=Subprocess.STREAM, stderr=subprocess.STDOUT,
                             io_loop=self.io_loop)
        self.addCleanup(lambda: os.kill(subproc.pid, signal.SIGTERM))
        subproc.stdout.read_until(b'>>> ', self.stop)
        self.wait()
        subproc.stdin.close()
        subproc.stdout.read_until_close(self.stop)
        data = self.wait()
        self.assertEqual(data, b"\n") 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:15,代碼來源:process_test.py

示例5: test_stderr

# 需要導入模塊: from tornado.process import Subprocess [as 別名]
# 或者: from tornado.process.Subprocess import STREAM [as 別名]
def test_stderr(self):
        subproc = Subprocess([sys.executable, '-u', '-c',
                              r"import sys; sys.stderr.write('hello\n')"],
                             stderr=Subprocess.STREAM,
                             io_loop=self.io_loop)
        self.addCleanup(lambda: os.kill(subproc.pid, signal.SIGTERM))
        subproc.stderr.read_until(b'\n', self.stop)
        data = self.wait()
        self.assertEqual(data, b'hello\n') 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:11,代碼來源:process_test.py

示例6: test_subprocess

# 需要導入模塊: from tornado.process import Subprocess [as 別名]
# 或者: from tornado.process.Subprocess import STREAM [as 別名]
def test_subprocess(self):
        if IOLoop.configured_class().__name__.endswith("LayeredTwistedIOLoop"):
            # This test fails non-deterministically with LayeredTwistedIOLoop.
            # (the read_until('\n') returns '\n' instead of 'hello\n')
            # This probably indicates a problem with either TornadoReactor
            # or TwistedIOLoop, but I haven't been able to track it down
            # and for now this is just causing spurious travis-ci failures.
            raise unittest.SkipTest(
                "Subprocess tests not compatible with " "LayeredTwistedIOLoop"
            )
        subproc = Subprocess(
            [sys.executable, "-u", "-i"],
            stdin=Subprocess.STREAM,
            stdout=Subprocess.STREAM,
            stderr=subprocess.STDOUT,
        )
        self.addCleanup(lambda: self.term_and_wait(subproc))
        self.addCleanup(subproc.stdout.close)
        self.addCleanup(subproc.stdin.close)
        yield subproc.stdout.read_until(b">>> ")
        subproc.stdin.write(b"print('hello')\n")
        data = yield subproc.stdout.read_until(b"\n")
        self.assertEqual(data, b"hello\n")

        yield subproc.stdout.read_until(b">>> ")
        subproc.stdin.write(b"raise SystemExit\n")
        data = yield subproc.stdout.read_until_close()
        self.assertEqual(data, b"") 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:30,代碼來源:process_test.py

示例7: test_close_stdin

# 需要導入模塊: from tornado.process import Subprocess [as 別名]
# 或者: from tornado.process.Subprocess import STREAM [as 別名]
def test_close_stdin(self):
        # Close the parent's stdin handle and see that the child recognizes it.
        subproc = Subprocess(
            [sys.executable, "-u", "-i"],
            stdin=Subprocess.STREAM,
            stdout=Subprocess.STREAM,
            stderr=subprocess.STDOUT,
        )
        self.addCleanup(lambda: self.term_and_wait(subproc))
        yield subproc.stdout.read_until(b">>> ")
        subproc.stdin.close()
        data = yield subproc.stdout.read_until_close()
        self.assertEqual(data, b"\n") 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:15,代碼來源:process_test.py

示例8: test_stderr

# 需要導入模塊: from tornado.process import Subprocess [as 別名]
# 或者: from tornado.process.Subprocess import STREAM [as 別名]
def test_stderr(self):
        # This test is mysteriously flaky on twisted: it succeeds, but logs
        # an error of EBADF on closing a file descriptor.
        subproc = Subprocess(
            [sys.executable, "-u", "-c", r"import sys; sys.stderr.write('hello\n')"],
            stderr=Subprocess.STREAM,
        )
        self.addCleanup(lambda: self.term_and_wait(subproc))
        data = yield subproc.stderr.read_until(b"\n")
        self.assertEqual(data, b"hello\n")
        # More mysterious EBADF: This fails if done with self.addCleanup instead of here.
        subproc.stderr.close() 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:14,代碼來源:process_test.py

示例9: test_sigchild_signal

# 需要導入模塊: from tornado.process import Subprocess [as 別名]
# 或者: from tornado.process.Subprocess import STREAM [as 別名]
def test_sigchild_signal(self):
        Subprocess.initialize()
        self.addCleanup(Subprocess.uninitialize)
        subproc = Subprocess(
            [sys.executable, "-c", "import time; time.sleep(30)"],
            stdout=Subprocess.STREAM,
        )
        self.addCleanup(subproc.stdout.close)
        subproc.set_exit_callback(self.stop)
        os.kill(subproc.pid, signal.SIGTERM)
        try:
            ret = self.wait(timeout=1.0)
        except AssertionError:
            # We failed to get the termination signal. This test is
            # occasionally flaky on pypy, so try to get a little more
            # information: did the process close its stdout
            # (indicating that the problem is in the parent process's
            # signal handling) or did the child process somehow fail
            # to terminate?
            fut = subproc.stdout.read_until_close()
            fut.add_done_callback(lambda f: self.stop())  # type: ignore
            try:
                self.wait(timeout=1.0)
            except AssertionError:
                raise AssertionError("subprocess failed to terminate")
            else:
                raise AssertionError(
                    "subprocess closed stdout but failed to " "get termination signal"
                )
        self.assertEqual(subproc.returncode, ret)
        self.assertEqual(ret, -signal.SIGTERM) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:33,代碼來源:process_test.py

示例10: test_close_stdin

# 需要導入模塊: from tornado.process import Subprocess [as 別名]
# 或者: from tornado.process.Subprocess import STREAM [as 別名]
def test_close_stdin(self):
        # Close the parent's stdin handle and see that the child recognizes it.
        subproc = Subprocess([sys.executable, '-u', '-i'],
                             stdin=Subprocess.STREAM,
                             stdout=Subprocess.STREAM, stderr=subprocess.STDOUT)
        self.addCleanup(lambda: (subproc.proc.terminate(), subproc.proc.wait()))
        yield subproc.stdout.read_until(b'>>> ')
        subproc.stdin.close()
        data = yield subproc.stdout.read_until_close()
        self.assertEqual(data, b"\n") 
開發者ID:tp4a,項目名稱:teleport,代碼行數:12,代碼來源:process_test.py

示例11: test_stderr

# 需要導入模塊: from tornado.process import Subprocess [as 別名]
# 或者: from tornado.process.Subprocess import STREAM [as 別名]
def test_stderr(self):
        # This test is mysteriously flaky on twisted: it succeeds, but logs
        # an error of EBADF on closing a file descriptor.
        skip_if_twisted()
        subproc = Subprocess([sys.executable, '-u', '-c',
                              r"import sys; sys.stderr.write('hello\n')"],
                             stderr=Subprocess.STREAM)
        self.addCleanup(lambda: (subproc.proc.terminate(), subproc.proc.wait()))
        data = yield subproc.stderr.read_until(b'\n')
        self.assertEqual(data, b'hello\n')
        # More mysterious EBADF: This fails if done with self.addCleanup instead of here.
        subproc.stderr.close() 
開發者ID:tp4a,項目名稱:teleport,代碼行數:14,代碼來源:process_test.py

示例12: test_sigchild_signal

# 需要導入模塊: from tornado.process import Subprocess [as 別名]
# 或者: from tornado.process.Subprocess import STREAM [as 別名]
def test_sigchild_signal(self):
        skip_if_twisted()
        Subprocess.initialize()
        self.addCleanup(Subprocess.uninitialize)
        subproc = Subprocess([sys.executable, '-c',
                              'import time; time.sleep(30)'],
                             stdout=Subprocess.STREAM)
        self.addCleanup(subproc.stdout.close)
        subproc.set_exit_callback(self.stop)
        os.kill(subproc.pid, signal.SIGTERM)
        try:
            ret = self.wait(timeout=1.0)
        except AssertionError:
            # We failed to get the termination signal. This test is
            # occasionally flaky on pypy, so try to get a little more
            # information: did the process close its stdout
            # (indicating that the problem is in the parent process's
            # signal handling) or did the child process somehow fail
            # to terminate?
            subproc.stdout.read_until_close(callback=self.stop)
            try:
                self.wait(timeout=1.0)
            except AssertionError:
                raise AssertionError("subprocess failed to terminate")
            else:
                raise AssertionError("subprocess closed stdout but failed to "
                                     "get termination signal")
        self.assertEqual(subproc.returncode, ret)
        self.assertEqual(ret, -signal.SIGTERM) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:31,代碼來源:process_test.py

示例13: run_command_async

# 需要導入模塊: from tornado.process import Subprocess [as 別名]
# 或者: from tornado.process.Subprocess import STREAM [as 別名]
def run_command_async(cmd):
    """
    Run a command using the asynchronous `tornado.process.Subprocess`.

    Parameters
    ----------
    iterable
        An iterable of command-line arguments to run in the subprocess.

    Returns
    -------
    A tuple containing the (return code, stdout)
    """
    process = Subprocess(cmd,
                         stdout=Subprocess.STREAM,
                         stderr=Subprocess.STREAM)
    try:
        yield process.wait_for_exit()
    except CalledProcessError as err:
        pass
    code = process.returncode
    out = yield process.stdout.read_until_close()
    return (code, out.decode('utf-8'))

# Windows does not support async subprocesses, so
# use a synchronous system calls. 
開發者ID:jupyterlab,項目名稱:jupyterlab-latex,代碼行數:28,代碼來源:util.py


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