本文整理汇总了Python中tornado.process.Subprocess.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Subprocess.__init__方法的具体用法?Python Subprocess.__init__怎么用?Python Subprocess.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.process.Subprocess
的用法示例。
在下文中一共展示了Subprocess.__init__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import __init__ [as 别名]
def __init__(
self,
command,
timeout=-1,
stdout_chunk_callback=None,
stderr_chunk_callback=None,
exit_process_callback=None,
stdin_bytes=None,
io_loop=None,
kill_on_timeout=False
):
"""
Initializes the subprocess with callbacks and timeout.
:param command: command like ['java', '-jar', 'test.jar']
:param timeout: timeout for subprocess to complete, if negative or \
zero then no timeout
:param stdout_chunk_callback: callback(bytes_data_chuck_from_stdout)
:param stderr_chunk_callback: callback(bytes_data_chuck_from_stderr)
:param exit_process_callback: callback(exit_code, \
was_expired_by_timeout)
:param stdin_bytes: bytes data to send to stdin
:param io_loop: tornado io loop on None for current
:param kill_on_timeout: kill(-9) or terminate(-15)?
"""
self.aa_exit_process_callback = exit_process_callback
self.aa_kill_on_timeout = kill_on_timeout
stdin = Subprocess.STREAM if stdin_bytes else None
stdout = Subprocess.STREAM if stdout_chunk_callback else None
stderr = Subprocess.STREAM if stderr_chunk_callback else None
Subprocess.__init__(self, command, stdin=stdin, stdout=stdout,
stderr=stderr, io_loop=io_loop)
self.aa_process_expired = False
self.aa_terminate_timeout = self.io_loop.call_later(
timeout, self.aa_timeout_callback) if timeout > 0 else None
self.set_exit_callback(self.aa_exit_callback)
if stdin:
self.stdin.write(stdin_bytes)
self.stdin.close()
if stdout:
output_stream = PipeIOStream(self.stdout.fileno())
def on_stdout_chunk(data):
stdout_chunk_callback(data)
if not output_stream.closed():
output_stream.read_bytes(102400,
on_stdout_chunk, None, True)
output_stream.read_bytes(102400, on_stdout_chunk, None, True)
if stderr:
stderr_stream = PipeIOStream(self.stderr.fileno())
def on_stderr_chunk(data):
stderr_chunk_callback(data)
if not stderr_stream.closed():
stderr_stream.read_bytes(102400,
on_stderr_chunk, None, True)
stderr_stream.read_bytes(102400, on_stderr_chunk, None, True)