Twisted pipe two processes with spawnProcess

自作多情 提交于 2019-12-11 10:04:54

问题


I'm trying to use Twisted with Python2.7 for piping two processes.

What I'd like to do is:

myImagesPipesGenerator | ffmpeg -i -

myImagesPipesGenerator is outputing on stdout an infinite list of BMP images. FFmpeg is getting those pictures on stdin and encoding them in a video

So I need to:

generatorTransport = reactor.spawnProcess(myInputProtocol, "myImagesPipesGenerator", ["myImagesPipesGenerator",], env=None, childFDs={0:'w', 1:'r', 2:'r'})
ffmpegTransport = reactor.spawnProcess(myOutputProtocol, "ffmpeg", ["ffmpeg","-i","-"], env=None, childFDs={0:__What_to_use_here__, 1:'r', 2:'r'})

How to get the "output" file descriptor of generatorTransport stdout pipe, so I can use it in childFDs for ffmpegTransport?

Thanks for your help,


回答1:


Create the pipe yourself:

read, write = os.pipe()

And then pass the file descriptors where you want the children to use them. Something like:

generatorTransport = reactor.spawnProcess(..., childFDs={1: write})
ffmpegTransport = reactor.spawnProcess(..., childFDs={0: read})


来源:https://stackoverflow.com/questions/23012265/twisted-pipe-two-processes-with-spawnprocess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!