0
運行此代碼pyuv產卵一個過程,捕獲其輸出和錯誤:爲什麼pyuv.pipe.start_read(...)在pyuv.process.spawn上導致Segementation錯誤?
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pyuv
def on_read(pipe, data, error):
print('data: ' + str(data))
def on_exit(process, exit_status, term_signal):
print('Process Terminated - exit code: ' + str(exit_status))
def start():
stdin_pipe = pyuv.Pipe(pyuv.Loop.default_loop())
stdout_pipe = pyuv.Pipe(pyuv.Loop.default_loop())
stderr_pipe = pyuv.Pipe(pyuv.Loop.default_loop())
stdout_pipe.start_read(on_read)
stderr_pipe.start_read(on_read)
stdio = [pyuv.StdIO(stream=stdin_pipe, flags=pyuv.UV_CREATE_PIPE | pyuv.UV_READABLE_PIPE),
pyuv.StdIO(stream=stdout_pipe, flags=pyuv.UV_CREATE_PIPE | pyuv.UV_WRITABLE_PIPE),
pyuv.StdIO(stream=stderr_pipe, flags=pyuv.UV_CREATE_PIPE | pyuv.UV_WRITABLE_PIPE)]
process = pyuv.Process(pyuv.Loop.default_loop())
process.spawn(loop=pyuv.Loop.default_loop(),
args=['/usr/bin/wget', 'http://www.google.com'],
exit_callback=on_exit,
stdio=stdio)
pyuv.Loop.default_loop().run()
if __name__ == '__main__':
start()
產生一個Segmentation fault (core dumped)
談到了「start_read()調用的管道實例的作品,但不給我是stdout和stderr。
我缺少什麼?
這是不是正確的方式來捕獲pyuv派生進程的標準輸出和標準錯誤?