Python tornado.process.Subprocess.STREAM Examples
The following are 30
code examples of tornado.process.Subprocess.STREAM().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tornado.process.Subprocess
, or try the search function
.
Example #1
Source File: process_test.py From pySINDy with MIT License | 6 votes |
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"")
Example #2
Source File: process_test.py From teleport with Apache License 2.0 | 6 votes |
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"")
Example #3
Source File: process_test.py From viewfinder with Apache License 2.0 | 6 votes |
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"")
Example #4
Source File: process_test.py From viewfinder with Apache License 2.0 | 6 votes |
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"")
Example #5
Source File: process_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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"")
Example #6
Source File: util.py From jupyterlab-latex with BSD 3-Clause "New" or "Revised" License | 5 votes |
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.
Example #7
Source File: process_test.py From pySINDy with MIT License | 5 votes |
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")
Example #8
Source File: process_test.py From pySINDy with MIT License | 5 votes |
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()
Example #9
Source File: process_test.py From pySINDy with MIT License | 5 votes |
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)
Example #10
Source File: process_test.py From teleport with Apache License 2.0 | 5 votes |
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")
Example #11
Source File: process_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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")
Example #12
Source File: process_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
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')
Example #13
Source File: process_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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"")
Example #14
Source File: process_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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")
Example #15
Source File: process_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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()
Example #16
Source File: process_test.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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)
Example #17
Source File: spawner.py From sudospawner with BSD 3-Clause "New" or "Revised" License | 5 votes |
def do(self, action, **kwargs): """Instruct the mediator process to take a given action""" kwargs['action'] = action cmd = ['sudo', '-u', self.user.name] cmd.extend(self.sudo_args) cmd.append(self.sudospawner_path) if self.debug_mediator: self.mediator_log_level = 'DEBUG' warnings.warn("debug_mediator is deprecated in favor of mediator_log_level", DeprecationWarning) if self.mediator_log_level: cmd.append('--logging={}'.format(self.mediator_log_level)) self.log.debug("Spawning %s", cmd) p = Subprocess(cmd, stdin=Subprocess.STREAM, stdout=Subprocess.STREAM, stderr=Subprocess.STREAM, preexec_fn=self.make_preexec_fn()) stderr_future = self.relog_stderr(p.stderr) # hand the stderr future to the IOLoop so it isn't orphaned, # even though we aren't going to wait for it unless there's an error IOLoop.current().add_callback(lambda : stderr_future) yield p.stdin.write(json.dumps(kwargs).encode('utf8')) p.stdin.close() data = yield p.stdout.read_until_close() if p.returncode: yield stderr_future raise RuntimeError("sudospawner subprocess failed with exit code: %r" % p.returncode) data_str = data.decode('utf8', 'replace') try: data_str = data_str[data_str.index('{'):data_str.rindex('}')+1] response = json.loads(data_str) except ValueError: self.log.error("Failed to get JSON result from mediator: %r" % data_str) raise return response
Example #18
Source File: process_test.py From teleport with Apache License 2.0 | 5 votes |
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)
Example #19
Source File: process_test.py From teleport with Apache License 2.0 | 5 votes |
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()
Example #20
Source File: process_test.py From tornado-zh with MIT License | 5 votes |
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"")
Example #21
Source File: process_test.py From viewfinder with Apache License 2.0 | 5 votes |
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")
Example #22
Source File: process_test.py From viewfinder with Apache License 2.0 | 5 votes |
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')
Example #23
Source File: process_test.py From viewfinder with Apache License 2.0 | 5 votes |
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")
Example #24
Source File: process_test.py From opendevops with GNU General Public License v3.0 | 5 votes |
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)
Example #25
Source File: process_test.py From opendevops with GNU General Public License v3.0 | 5 votes |
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()
Example #26
Source File: process_test.py From opendevops with GNU General Public License v3.0 | 5 votes |
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")
Example #27
Source File: process_test.py From opendevops with GNU General Public License v3.0 | 5 votes |
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"")
Example #28
Source File: process_test.py From tornado-zh with MIT License | 5 votes |
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")
Example #29
Source File: process_test.py From tornado-zh with MIT License | 5 votes |
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"")
Example #30
Source File: process_test.py From tornado-zh with MIT License | 5 votes |
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')